Fix bug in which we were running out of file descriptors. (#91)

This commit is contained in:
Robert Nishihara
2016-12-05 23:45:49 -08:00
committed by Philipp Moritz
parent ba53e4a43a
commit dd39008532
4 changed files with 25 additions and 3 deletions
+3
View File
@@ -94,6 +94,9 @@ class PlasmaClient(object):
size (int): The size in bytes of the created buffer.
metadata (buffer): An optional buffer encoding whatever metadata the user
wishes to encode.
Raises:
Exception: An exception is raised if the object could not be created.
"""
# Turn the metadata into the right type.
metadata = bytearray("") if metadata is None else metadata
+2
View File
@@ -196,6 +196,7 @@ bool plasma_create(plasma_connection *conn,
CHECKM(fd >= 0, "recv not successful");
if (reply.error_code == PLASMA_OBJECT_ALREADY_EXISTS) {
LOG_DEBUG("returned from plasma_create with error %d", reply.error_code);
close(fd);
return false;
}
plasma_object *object = &reply.object;
@@ -630,6 +631,7 @@ bool plasma_get_local(plasma_connection *conn,
if (!reply.has_object) {
/* The object is not in our local store. */
close(fd);
return false;
}
object = &reply.object;
+8 -3
View File
@@ -65,9 +65,14 @@ PyObject *PyPlasma_create(PyObject *self, PyObject *args) {
return NULL;
}
uint8_t *data;
plasma_create(conn, object_id, size,
(uint8_t *) PyByteArray_AsString(metadata),
PyByteArray_Size(metadata), &data);
bool created = plasma_create(conn, object_id, size,
(uint8_t *) PyByteArray_AsString(metadata),
PyByteArray_Size(metadata), &data);
if (!created) {
PyErr_SetString(PyExc_RuntimeError,
"an object with this ID could not be created");
return NULL;
}
return PyBuffer_FromReadWriteMemory((void *) data, (Py_ssize_t) size);
}
+12
View File
@@ -121,6 +121,18 @@ class TestPlasmaClient(unittest.TestCase):
for i in range(len(metadata)):
self.assertEqual(metadata[i], metadata_buffer[i])
def test_create_existing(self):
# This test is partially used to test the code path in which we create an
# object with an ID that already exists
length = 100
for _ in range(1000):
object_id = random_object_id()
self.plasma_client.create(object_id, length, generate_metadata(length))
try:
val = self.plasma_client.create(object_id, length, generate_metadata(length))
except Exception:
pass
def test_contains(self):
fake_object_ids = [random_object_id() for _ in range(100)]
real_object_ids = [random_object_id() for _ in range(100)]