Skip to content
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

[CLIENT-2887] Fix aerospike.Client() segfaulting when it fails to connect #608

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/client/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,6 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args,
self->as = aerospike_new(&config);

if (AerospikeClientConnect(self) == -1) {
aerospike_destroy(self->as);
return -1;
}

Expand Down Expand Up @@ -1368,6 +1367,6 @@ AerospikeClient *AerospikeClient_New(PyObject *parent, PyObject *args,
raise_exception(&err);

CLEANUP:
AerospikeClient_Type.tp_free(self);
AerospikeClient_Type.tp_dealloc((PyObject *)self);
return NULL;
}
21 changes: 21 additions & 0 deletions test/new_tests/test_new_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from aerospike_helpers.batch.records import Write, BatchRecords
from .test_scan_execute_background import wait_for_job_completion
import copy
from contextlib import nullcontext

gconfig = {}
gconfig = TestBaseClass.get_connection_config()
Expand Down Expand Up @@ -385,3 +386,23 @@ def test_invalid_read_touch_ttl_percent(self, policy_name: str):
with pytest.raises(e.ParamError) as excinfo:
aerospike.client(config)
assert excinfo.value.msg == "Invalid Policy setting value"

@pytest.mark.parametrize(
"config, context",
[
(
gconfig,
nullcontext()
),
(
{
"hosts": [("invalid-host", 4000)]
},
# Tests that fail to connect should expect any of these exceptions
pytest.raises((e.ConnectionError, e.TimeoutError, e.ClientError))
)
]
)
def test_client_class_constructor(self, config: dict, context):
with context:
aerospike.Client(config)
Loading