-
Notifications
You must be signed in to change notification settings - Fork 199
Fix driver stuck on RecursionError on COMMIT SUCCESS #1192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
robsdedude
merged 3 commits into
neo4j:6.x
from
robsdedude:fix/driver-stuck-on-recursion-error-in-commit-success
May 28, 2025
+1,080
−52
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) "Neo4j" | ||
# Neo4j Sweden AB [https://neo4j.com] | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# Copyright (c) "Neo4j" | ||
# Neo4j Sweden AB [https://neo4j.com] | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import asyncio | ||
|
||
import pytest | ||
|
||
from neo4j._async.io._common import AsyncInbox | ||
from neo4j._codec.packstream.v1 import Unpacker | ||
from neo4j._exceptions import SocketDeadlineExceededError | ||
|
||
from ....._async_compat import mark_async_test | ||
|
||
|
||
class InboxMockHolder: | ||
def __init__(self, mocker): | ||
self.socket_mock = mocker.Mock() | ||
self.socket_mock.getsockname.return_value = ("host", 1234) | ||
self.on_error = mocker.AsyncMock() | ||
self.inbox = AsyncInbox(self.socket_mock, self.on_error, Unpacker) | ||
self.unpacker = mocker.Mock(wraps=self.inbox._unpacker) | ||
self.inbox._unpacker = self.unpacker | ||
# plenty of nonsense messages to read | ||
self.mock_set_data(b"\x00\x01\xff\x00\x00" * 1000) | ||
|
||
def mock_set_data(self, data): | ||
async def side_effect(buffer, n): | ||
nonlocal data | ||
|
||
if not data: | ||
pytest.fail("Read more data than mocked") | ||
|
||
n = min(len(data), len(buffer), n) | ||
buffer[:n] = data[:n] | ||
data = data[n:] | ||
return n | ||
|
||
self.socket_mock.recv_into.side_effect = side_effect | ||
|
||
def assert_no_error(self): | ||
self.on_error.assert_not_called() | ||
assert not self.inbox._broken | ||
|
||
def mock_receive_failure(self, exception): | ||
self.socket_mock.recv_into.side_effect = exception | ||
|
||
def mock_unpack_failure(self, exception): | ||
self.unpacker.unpack_structure_header.side_effect = exception | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("data", "result"), | ||
( | ||
( | ||
bytes((0, 2, 10, 11, 0, 2, 12, 13, 0, 1, 14, 0, 0)), | ||
bytes(range(10, 15)), | ||
), | ||
( | ||
bytes((0, 2, 10, 11, 0, 2, 12, 13, 0, 0)), | ||
bytes(range(10, 14)), | ||
), | ||
( | ||
bytes((0, 1, 5, 0, 0)), | ||
bytes((5,)), | ||
), | ||
), | ||
) | ||
@mark_async_test | ||
async def test_inbox_dechunking(data, result, mocker): | ||
# Given | ||
mocks = InboxMockHolder(mocker) | ||
mocks.mock_set_data(data) | ||
inbox = mocks.inbox | ||
buffer = inbox._buffer | ||
|
||
# When | ||
await inbox._buffer_one_chunk() | ||
|
||
# Then | ||
mocks.assert_no_error() | ||
assert buffer.used == len(result) | ||
assert buffer.data[: len(result)] == result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"error", | ||
( | ||
asyncio.CancelledError("test"), | ||
SocketDeadlineExceededError("test"), | ||
OSError("test"), | ||
), | ||
) | ||
@mark_async_test | ||
async def test_inbox_receive_failure_error_handler(mocker, error): | ||
mocks = InboxMockHolder(mocker) | ||
mocks.mock_receive_failure(error) | ||
inbox = mocks.inbox | ||
|
||
with pytest.raises(type(error)) as exc: | ||
await inbox.pop({}) | ||
|
||
assert exc.value is error | ||
mocks.on_error.assert_awaited_once_with(error) | ||
assert inbox._broken | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"error", | ||
( | ||
SocketDeadlineExceededError("test"), | ||
OSError("test"), | ||
RecursionError("2deep4u"), | ||
RuntimeError("something funny happened"), | ||
), | ||
) | ||
@mark_async_test | ||
async def test_inbox_unpack_failure(mocker, error): | ||
mocks = InboxMockHolder(mocker) | ||
mocks.mock_unpack_failure(error) | ||
inbox = mocks.inbox | ||
|
||
with pytest.raises(type(error)) as exc: | ||
await inbox.pop({}) | ||
|
||
assert exc.value is error | ||
mocks.on_error.assert_awaited_once_with(error) | ||
assert inbox._broken |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.