Skip to content

Commit

Permalink
[CLIENT-2887] Fix aerospike.Client() segfaulting when it fails to con…
Browse files Browse the repository at this point in the history
…nect (#608)
  • Loading branch information
juliannguyen4 authored May 9, 2024
1 parent a685ba9 commit 7495e35
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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)

0 comments on commit 7495e35

Please sign in to comment.