exasol / pyexasol

Exasol Python driver with low overhead, fast HTTP transport and compression
MIT License
72 stars 39 forks source link

pyexasol not raising an Exception on Exasol error #93

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hello,

when the query runs into an error, instead of raising an exception the script hangs forever. I'm still on Protocol v1 in case it matters. Debug output looks like this, one hour afterwards the script still hangs:

2022-08-03 16:28:40.815 [WebSocket response #4]
{
  "exception": {
    "sqlCode": "42500",
    "text": "insufficient privileges: SELECT on table [censored](Session: 1740150585646001936)"
  },
  "status": "error"
}
littleK0i commented 2 years ago

Is it a normal "SELECT" statement or is it an HTTP transport wrapped statement (like .export_to_pandas())?

I see how it might be happening to HTTP transport, but it would be very odd for normal statement. Here is the place in code which writes log message you've mentioned, and it is guaranteed to raise an exception afterwards if status == error: https://github.com/exasol/pyexasol/blob/c9b1f445d1f1424b8cf9aaa7b42945c935fdbb0e/pyexasol/connection.py#L539-L562

ghost commented 2 years ago

actually it is an .export_to_file statement

littleK0i commented 2 years ago

Is it OS Windows?

Here is the code which closes pipes in case of exception: https://github.com/exasol/pyexasol/blob/c9b1f445d1f1424b8cf9aaa7b42945c935fdbb0e/pyexasol/http_transport.py#L253-L260

Which should terminate copyfileobj call in the main thread due to BrokenPipe: https://github.com/exasol/pyexasol/blob/master/pyexasol/callback.py#L52

Hmm, that's odd.

littleK0i commented 2 years ago

Does it reproduce for .export_to_pandas()?

ghost commented 2 years ago

.export_to_pandas raise the exception correctly.

ghost commented 2 years ago

Oh and the OS is Windows 10

littleK0i commented 2 years ago

I'll have access to Win10 machine this weekend. I'll try to reproduce and add a workaround.

If you'll have a chance to post a reply, could you also add a Python version? I suspect, something was changed in copyfileobj implementation for Windows in recent versions.

ghost commented 2 years ago

actually I'm still on Python 3.7 since this is what we use in production at the moment

littleK0i commented 2 years ago

@xyxz-web , please check the latest version 0.25.0. This specific problem should no longer occur on Windows.

In theory, it should be possible to remove pipes altogether and use some sort of Python native FIFO binary buffer instead. We may consider implementing it if problems with Windows pipes continue.

ghost commented 2 years ago

Looks good, the following test is now green:

(...)
            with pytest.raises(pyexasol.exceptions.ExaQueryError):
                conn.export_to_pandas("asdf")