tarantool / tarantool-python

Python client library for Tarantool
https://www.tarantool.io
BSD 2-Clause "Simplified" License
101 stars 46 forks source link

Occasional crashes #75

Closed gafusss closed 8 years ago

gafusss commented 8 years ago

Tarantool 1.6.8-725-g620b89f + tarantool-python 0.5.4 + python 2.7.8 Crashes occasionally on length = msgpack.unpackb(self._recv(5)) with raise UnpackValueError("Data is not enough.")

Might be related to #51

bigbes commented 8 years ago

I need some kind of testcase for this. Do you have more than 2^32 returned data? Server always returns 5 bytes length

gafusss commented 8 years ago

Do you have more than 2^32 returned data

No, I dont

I did some testing. I believe the error occurs on concurrent use of the same Connection. If two processes try to self._recv(5) simultaneously upon recieving response from Tarantool, things will go south.

gafusss commented 8 years ago
from os import fork
from tarantool import Connection

c = Connection("127.0.0.1", 3301)

fork()

while True:
    print(c.select('filters'))

This crashes immediately for me.

Traceback (most recent call last):
  File "conntest.py", line 9, in <module>
Traceback (most recent call last):
    print(c.select('filters'))
  File "conntest.py", line 9, in <module>
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/connection.py", line 677, in select
    print(c.select('filters'))
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/connection.py", line 677, in select
    space_name = self.schema.get_space(space_name).sid
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/schema.py", line 75, in get_space
    space_row = self.con.select(const.SPACE_VSPACE, space, index=_index)
    space_name = self.schema.get_space(space_name).sid
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/connection.py", line 682, in select
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/schema.py", line 75, in get_space
    space_row = self.con.select(const.SPACE_VSPACE, space, index=_index)
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/connection.py", line 682, in select
    response = self._send_request(request)
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/connection.py", line 292, in _send_request
    response = self._send_request(request)
    request)
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/connection.py", line 292, in _send_request
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/connection.py", line 211, in _send_request_wo_reconnect
    response = Response(self, self._read_response())
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/response.py", line 52, in __init__
    request)
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/connection.py", line 211, in _send_request_wo_reconnect
    self._sync = header.get(IPROTO_SYNC, 0)
AttributeError: 'int' object has no attribute 'get'
    response = Response(self, self._read_response())
  File "/home/sq/sq/env/lib/python2.7/site-packages/tarantool/connection.py", line 195, in _read_response
    length = msgpack.unpackb(self._recv(5))
  File "/home/sq/sq/env/lib/python2.7/site-packages/msgpack/fallback.py", line 98, in unpackb
    raise UnpackValueError("Data is not enough.")
msgpack.exceptions.UnpackValueError: Data is not enough.
bigbes commented 8 years ago

@gafusss this driver can't support single connection for multiple process. Structure of a driver must be something like in gtarantool/tarantool-aio. One thread for reading/writing. Locks when working with io buffer, locks of waiting for an answer/futures. This driver is synchronous, so it can't be fixed.

gafusss commented 8 years ago

@bigbes Thank you, but you might want to add this to the docs, if it isn't already there, since it's not so obvious

bigbes commented 8 years ago

@gafusss Of, course. I'll do this, thanks.

bigbes commented 8 years ago

@gafusss If you have some ideas on multiprocessing/threaded driver - you can contact me via email in my profile or open ticket. Feel free to open PR.