Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed unreferencing the loop too early after calling close

  • Loading branch information...
commit 5ef7fbf161445363faa31ad181fd22440c39a4d0 1 parent 4784e6e
@saghul authored
Showing with 40 additions and 4 deletions.
  1. +4 −4 src/handle.c
  2. +36 −0 tests/test_tcp.py
View
8 src/handle.c
@@ -25,6 +25,10 @@ on_handle_close(uv_handle_t *handle)
Py_XDECREF(self->on_close_cb);
self->on_close_cb = NULL;
+ Py_DECREF(self->loop);
+ self->loop = (Loop *)Py_None;
+ Py_INCREF(Py_None);
+
/* Refcount was increased in the caller function */
Py_DECREF(self);
@@ -80,10 +84,6 @@ Handle_func_close(Handle *self, PyObject *args)
Py_XINCREF(callback);
self->on_close_cb = callback;
- Py_DECREF(self->loop);
- self->loop = (Loop *)Py_None;
- Py_INCREF(Py_None);
-
/* Increase refcount so that object is not removed before the callback is called */
Py_INCREF(self);
View
36 tests/test_tcp.py
@@ -88,6 +88,42 @@ def test_tcp1(self):
self.loop.run()
+class TCPTest2(unittest2.TestCase):
+
+ def setUp(self):
+ self.loop = pyuv.Loop.default_loop()
+ self.server = None
+ self.client = None
+ self.write_cb_count = 0
+
+ def on_connection(self, server, error):
+ self.assertEqual(error, None)
+ client = pyuv.TCP(pyuv.Loop.default_loop())
+ server.accept(client)
+ for x in range(1024):
+ client.write(b"PING"*1000, self.on_client_write)
+ client.close()
+ server.close()
+
+ def on_client_connection(self, client, error):
+ self.assertEqual(error, None)
+ self.assertTrue(client.readable)
+ self.assertTrue(client.writable)
+
+ def on_client_write(self, handle, error):
+ self.assertTrue(error in (None, pyuv.errno.UV_ECANCELED))
+ self.write_cb_count += 1
+
+ def test_tcp_write_cancel(self):
+ self.server = pyuv.TCP(self.loop)
+ self.server.bind(("0.0.0.0", TEST_PORT))
+ self.server.listen(self.on_connection)
+ self.client = pyuv.TCP(self.loop)
+ self.client.connect(("127.0.0.1", TEST_PORT), self.on_client_connection)
+ self.loop.run()
+ self.assertEqual(self.write_cb_count, 1024)
+
+
class TCPTestUnicode(unittest2.TestCase):
def setUp(self):
Please sign in to comment.
Something went wrong with that request. Please try again.