Skip to content

Commit da58ba2

Browse files
author
Zhen
committed
Fixed the infinite running error
Removed some old stale files in the resources folder There is an infinite loop in `session._begin_tx` method where a tx is created before a conn is really established. As a result, if the server went down before the session is closed, then in `session._close`, the session will see a tx should be rolled back and blocks infinitly on `tx._roll_back.consume` as no record will ever return. This PR makes sure that in `session._begin_tx`, a tx is created after a conn is established.
1 parent 6297ea6 commit da58ba2

20 files changed

+19
-105
lines changed

neo4j/bolt/connection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ def connect(address, ssl_context=None, **config):
458458
raise ServiceUnavailable("Failed to establish connection to {!r}".format(address))
459459
else:
460460
raise
461+
except ConnectionResetError:
462+
raise ServiceUnavailable("Failed to establish connection to {!r}".format(address))
461463

462464
# Secure the connection if an SSL context has been provided
463465
if ssl_context and SSL_AVAILABLE:
@@ -500,7 +502,10 @@ def connect(address, ssl_context=None, **config):
500502
ready_to_read, _, _ = select((s,), (), (), 0)
501503
while not ready_to_read:
502504
ready_to_read, _, _ = select((s,), (), (), 0)
503-
data = s.recv(4)
505+
try:
506+
data = s.recv(4)
507+
except ConnectionResetError:
508+
raise ServiceUnavailable("Failed to read any data from server {!r} after connected".format(address))
504509
data_size = len(data)
505510
if data_size == 0:
506511
# If no data is returned after a successful select

neo4j/v1/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ def _run_transaction(self, access_mode, unit_of_work, *args, **kwargs):
425425
t0 = t1 = time()
426426
while t1 - t0 <= self._max_retry_time:
427427
try:
428-
self._create_transaction()
429428
self._connect(access_mode)
429+
self._create_transaction()
430430
self.__begin__()
431431
with self._transaction as tx:
432432
return unit_of_work(tx, *args, **kwargs)

test/examples/base_application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ def __init__(self, uri, user, password):
2525
self._driver = GraphDatabase.driver( uri, auth=( user, password ) )
2626

2727
def close(self):
28-
self._driver.close();
28+
self._driver.close()

test/examples/service_unavailable_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ def addItem(self):
3333
try:
3434
session.write_transaction(lambda tx: tx.run("CREATE (a:Item)"))
3535
return True
36-
except ServiceUnavailable as e:
36+
except ServiceUnavailable:
3737
return False
3838
# end::service-unavailable[]

test/resources/broken_router.script

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/resources/create_a.script

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/resources/disconnect_on_pull_all.script

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/resources/disconnect_on_run.script

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/resources/empty.script

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/resources/non_router.script

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)