You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Series.values.compute() leads to "TypeError: can't concat buffer to bytearray" #1179
Running a local dask-scheduler + dask-worker pair, the following code leads to a crash of the worker:
import dask.dataframe as dd
from dask.distributed import Executor
e = Executor('127.0.0.1:8786', set_as_default=True)
df = pd.DataFrame({"A": [1, 2, 3] * 10})
ddf = dd.from_pandas(df, npartitions=3)
ddf["A"].values.compute()
The worker crashes with:
Traceback (most recent call last):
File "/home/PHI-TPS/fkeller/.virtualenvs/dask/local/lib/python2.7/site-packages/distributed/core.py", line 259, in handle_comm
result = yield result
File "/home/PHI-TPS/fkeller/.virtualenvs/dask/local/lib/python2.7/site-packages/tornado/gen.py", line 1055, in run
value = future.result()
File "/home/PHI-TPS/fkeller/.virtualenvs/dask/local/lib/python2.7/site-packages/tornado/concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "/home/PHI-TPS/fkeller/.virtualenvs/dask/local/lib/python2.7/site-packages/tornado/gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "/home/PHI-TPS/fkeller/.virtualenvs/dask/local/lib/python2.7/site-packages/distributed/worker.py", line 439, in get_data
compressed = yield comm.write(msg)
File "/home/PHI-TPS/fkeller/.virtualenvs/dask/local/lib/python2.7/site-packages/tornado/gen.py", line 1055, in run
value = future.result()
File "/home/PHI-TPS/fkeller/.virtualenvs/dask/local/lib/python2.7/site-packages/tornado/concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "/home/PHI-TPS/fkeller/.virtualenvs/dask/local/lib/python2.7/site-packages/tornado/gen.py", line 292, in wrapper
result = func(*args, **kwargs)
File "/home/PHI-TPS/fkeller/.virtualenvs/dask/local/lib/python2.7/site-packages/distributed/comm/tcp.py", line 196, in write
stream.write(frame)
File "/home/PHI-TPS/fkeller/.virtualenvs/dask/local/lib/python2.7/site-packages/tornado/iostream.py", line 395, in write
self._write_buffer += data
TypeError: can't concat buffer to bytearray
Other computations like ddf["A"].compute() or even ddf.values.compute() work fine though.
I noticed that I can compute ddf["A"].values.compute() if I initialize with client = Client('127.0.0.1:8786') instead of using Executor. However then I get the worker crash on computing ddf["A"].unique().compute(), but only after successfully computing ddf["A"].values.compute() once. I can't really put my finger on whether it is related to the initialization, these specific operations, or even the order of operations.
The installation should be up-to-date versions of both dask + distributed. Client + scheduler + worker are all running from the same venv on the same host.
There was also a micro-release shortly after 1.17.1. This resolved some things with moving around memoryviews. I don't think that this is likely to affect you but you might try updating and see if that has an effect.
Updated to 1.17.1 but the worker still throws the exception with slightly modified behavior: I did get the computation result back in the client on the first attempt although the worker raised the exception. Repeating the command a second time hangs in the client. I feel that the issue manifests itself in a somewhat erratic way.
Lets wait for @pitrou to take a look at the error. He is more familiar with the networking stack than I am (I think he wrote the bytearray code in tornado) and may have thoughts. Unfortunately I think he's on vacation until Monday.
Adding a few more observations: Currently the frame in the the loop for frame in frames (distributed/comm/tcp.py line 192) are typically of type str, which is fine to pass on to Tornado's stream.write(frame). For some reason the frames list sometimes contains raw buffer objects, which Tornado can't handle. I can avoid the issue by a dirty fix like:
if "buffer" in type(frame).__name__:
stream.write(b"{}".format(frame))
else:
stream.write(frame)
But maybe that is not the right place to fix the issue and probably we still want to understand why the problem isn't easily reproducible.
Update: Maybe this isn't really a fix. It doesn't crash any more, but now my computation results differ from running with the single machine schedulers.
If I recall correctly we recently started allowing buffers and memoryviews through, but only if the stream supported them. Perhaps we're making this judgment incorrectly. This is definitely a situation where @pitrou would know more.
Ah, I think I found what is causing the issue: It might be related to allocators. I'm encountering the issue in a setting where the driver is using jemalloc while the scheduler/worker are using glibc. If I use glibc everywhere the issue disappears.
Same as in the other issue: I cannot reproduce the failures here with a newer jemalloc version / on OSX. I rather suspect that there is some usage of unitialised memory. This will probably not be a bug in distributed but one of the libraries it depends on that call native code.
Dang, I'm getting the TypeError: can't concat buffer to bytearray now in a pure glibc setting as well :(. But it takes more complex code now to trigger the issue, the simple example from above works. This is a tough issue.
Unfortunately, the issue you're having (concatenating a buffer to a bytearray) seems to have been fixed in Python 2.7.4... which was released more than 4 years ago.
I really recommend you upgrade to a recent bugfix release of Python 2.7. Continuum's Anaconda may help you with that.
So you are saying that from a networking perspective it does make sense that the frames list contains a buffer? I'm asking because it can't happen very often, otherwise it would be crashing all the time for me, and my impression was that this was maybe just a consequence of some other problem.
Because if it is a valid value it should be easy to fix this for Python 2.7.3 by properly converting to e.g. str or bytearray.
It is not so much about fixing the Python version locally on my machine. We still have a need to run on Debian 7 servers as well, which are also Python 2.7.3.
So you are saying that from a networking perspective it does make sense that the frames list contains a buffer?
It can make sense, yes. It means in some circumstance we were able to avoid a memory copy and instead passed a view of some existing memory area (most likely the data of a Numpy array). Why this only seems to happen sporadically for you I'm not sure, though.
Because if it is a valid value it should be easy to fix this for Python 2.7.3 by properly converting to e.g. str or bytearray.
It is initially easy, but then needs to be maintained. We are unlikely to run any CI builds with Python 2.7.3, so it may get broken unexpectedly again. Besides, without wanting to spread FUD, there are many other issues that were fixed in recent 2.7 releases and thay may pop up with 2.7.3 (basically anything that is above this line in Misc/NEWS).
Therefore I'm reluctant to add workarounds for such an old Python version, except if it's part of a commercial support contract.
The issue still exists, but we can close it for now. Possible work-arounds are not using jemalloc with Python 2.7.3 or using the patch posted above. If need be we can think about a PR either for Dask or maybe Tornado.
Activity
bluenote10 commentedon Jun 16, 2017
I noticed that I can compute
ddf["A"].values.compute()if I initialize withclient = Client('127.0.0.1:8786')instead of usingExecutor. However then I get the worker crash on computingddf["A"].unique().compute(), but only after successfully computingddf["A"].values.compute()once. I can't really put my finger on whether it is related to the initialization, these specific operations, or even the order of operations.mrocklin commentedon Jun 16, 2017
To be clear, Executor is just an alias to Client
This runs fine for me. My first guess is that you have a version mismatch. Can you verify that the following does not err:
bluenote10 commentedon Jun 16, 2017
That's the output I get:
The installation should be up-to-date versions of both dask + distributed. Client + scheduler + worker are all running from the same venv on the same host.
mrocklin commentedon Jun 16, 2017
I tried reproducing this with an environment like the following and unfortunately everything worked.
Any recommendations on what to check that might differ between our environments?
bluenote10 commentedon Jun 16, 2017
Maybe it's related to tornado, since that's where the error is thrown? My tornado version is
4.5.1.mrocklin commentedon Jun 16, 2017
Same
mrocklin commentedon Jun 16, 2017
There was also a micro-release shortly after 1.17.1. This resolved some things with moving around memoryviews. I don't think that this is likely to affect you but you might try updating and see if that has an effect.
bluenote10 commentedon Jun 16, 2017
Updated to 1.17.1 but the worker still throws the exception with slightly modified behavior: I did get the computation result back in the client on the first attempt although the worker raised the exception. Repeating the command a second time hangs in the client. I feel that the issue manifests itself in a somewhat erratic way.
Right now I have no idea what could be wrong...
mrocklin commentedon Jun 16, 2017
Lets wait for @pitrou to take a look at the error. He is more familiar with the networking stack than I am (I think he wrote the bytearray code in tornado) and may have thoughts. Unfortunately I think he's on vacation until Monday.
bluenote10 commentedon Jun 16, 2017
Adding a few more observations: Currently the
framein the the loopfor frame in frames(distributed/comm/tcp.py line 192) are typically of typestr, which is fine to pass on to Tornado'sstream.write(frame). For some reason the frames list sometimes contains rawbufferobjects, which Tornado can't handle. I can avoid the issue by a dirty fix like:But maybe that is not the right place to fix the issue and probably we still want to understand why the problem isn't easily reproducible.
Update: Maybe this isn't really a fix. It doesn't crash any more, but now my computation results differ from running with the single machine schedulers.
mrocklin commentedon Jun 16, 2017
If I recall correctly we recently started allowing
buffersandmemoryviewsthrough, but only if the stream supported them. Perhaps we're making this judgment incorrectly. This is definitely a situation where @pitrou would know more.bluenote10 commentedon Jun 20, 2017
Ah, I think I found what is causing the issue: It might be related to allocators. I'm encountering the issue in a setting where the driver is using jemalloc while the scheduler/worker are using glibc. If I use glibc everywhere the issue disappears.
xhochy commentedon Jun 20, 2017
Same as in the other issue: I cannot reproduce the failures here with a newer jemalloc version / on OSX. I rather suspect that there is some usage of unitialised memory. This will probably not be a bug in
distributedbut one of the libraries it depends on that call native code.bluenote10 commentedon Jun 20, 2017
Dang, I'm getting the
TypeError: can't concat buffer to bytearraynow in a pure glibc setting as well :(. But it takes more complex code now to trigger the issue, the simple example from above works. This is a tough issue.pitrou commentedon Jun 20, 2017
@bluenote10, which exact Python version are you using?
pitrou commentedon Jun 20, 2017
Oops, I see, it should be
2.7.3.final.0.pitrou commentedon Jun 20, 2017
Unfortunately, the issue you're having (concatenating a
bufferto abytearray) seems to have been fixed in Python 2.7.4... which was released more than 4 years ago.I really recommend you upgrade to a recent bugfix release of Python 2.7. Continuum's Anaconda may help you with that.
pitrou commentedon Jun 20, 2017
For the record:
bluenote10 commentedon Jun 20, 2017
So you are saying that from a networking perspective it does make sense that the
frameslist contains abuffer? I'm asking because it can't happen very often, otherwise it would be crashing all the time for me, and my impression was that this was maybe just a consequence of some other problem.Because if it is a valid value it should be easy to fix this for Python 2.7.3 by properly converting to e.g.
strorbytearray.It is not so much about fixing the Python version locally on my machine. We still have a need to run on Debian 7 servers as well, which are also Python 2.7.3.
pitrou commentedon Jun 20, 2017
It can make sense, yes. It means in some circumstance we were able to avoid a memory copy and instead passed a view of some existing memory area (most likely the data of a Numpy array). Why this only seems to happen sporadically for you I'm not sure, though.
pitrou commentedon Jun 21, 2017
It is initially easy, but then needs to be maintained. We are unlikely to run any CI builds with Python 2.7.3, so it may get broken unexpectedly again. Besides, without wanting to spread FUD, there are many other issues that were fixed in recent 2.7 releases and thay may pop up with 2.7.3 (basically anything that is above this line in
Misc/NEWS).Therefore I'm reluctant to add workarounds for such an old Python version, except if it's part of a commercial support contract.
mrocklin commentedon Jul 5, 2017
What is the status of this issue? Should it be closed?
bluenote10 commentedon Jul 5, 2017
The issue still exists, but we can close it for now. Possible work-arounds are not using jemalloc with Python 2.7.3 or using the patch posted above. If need be we can think about a PR either for Dask or maybe Tornado.