Skip to content

0.22.0 - object of type 'asyncpg.pgproto.pgproto.WriteBuffer' has no len() #700

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
rafalstapinski opened this issue Feb 12, 2021 · 5 comments · Fixed by #715
Closed

0.22.0 - object of type 'asyncpg.pgproto.pgproto.WriteBuffer' has no len() #700

rafalstapinski opened this issue Feb 12, 2021 · 5 comments · Fixed by #715
Assignees

Comments

@rafalstapinski
Copy link

rafalstapinski commented Feb 12, 2021

  • asyncpg version: 0.22.0
  • PostgreSQL version: 11
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    :
  • Python version: CPython 3.8.1
  • Platform: Ubuntu 18.04
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: pipenv
  • If you built asyncpg locally, which version of Cython did you use?: n/a
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : Running under uvloop

After having upgraded our underlying asyncpg version from 0.21.0 to 0.22.0 two days ago, every ~12 hours our http service has been running into an issue at which it can no longer connect to the database without restarting. The issue being reported is

StopIteration: null
  File "asyncpg/protocol/coreproto.pyx", line 945, in asyncpg.protocol.protocol.CoreProtocol._bind_execute_many_more
    buf = <WriteBuffer>next(self._execute_iter)

TypeError: object of type 'asyncpg.pgproto.pgproto.WriteBuffer' has no len()
  File "asyncpg/protocol/protocol.pyx", line 909, in asyncpg.protocol.protocol.BaseProtocol._writelines
    self.transport.writelines(buffers)
  File "uvloop/sslproto.pyx", line 163, in uvloop.loop._SSLProtocolTransport.writelines
    self._ssl_protocol._write_appdata(list_of_data, self.context.copy())
  File "uvloop/sslproto.pyx", line 652, in uvloop.loop.SSLProtocol._write_appdata
    self._write_buffer_size += len(data)

For context, we use tortoise-orm to interface with asyncpg.

@elprans
Copy link
Member

elprans commented Feb 12, 2021

@fantix Seems like bad interation of the new executemany code with TLS codepath in uvloop.

@khvn26
Copy link

khvn26 commented Feb 26, 2021

@ale-dd
Copy link

ale-dd commented Mar 5, 2021

I am hitting this issue as well, on 0.22.0 and using the new optimized executemany.

@fantix
Copy link
Member

fantix commented Mar 9, 2021

https://github.com/MagicStack/py-pgproto/blob/126bcd24bd3c59d581613dae026e2721efbedf16/buffer.pxd#L28 Shouldn't this be __len__?

That's indeed the issue I think. Though I'm not sure if we want to pass over the WriterBuffer directly to the transport - wrapping into a memoryview probably makes more sense.

fantix added a commit to fantix/asyncpg that referenced this issue Mar 9, 2021
This fixes an issue in 0.22.0 where we passed WriteBuffer to writelines
by mistake, which leads to an error under SSL and uvloop - the
implementation that calls len() on each line of writelines().

Fixes: MagicStack#700
elprans pushed a commit that referenced this issue Mar 9, 2021
This fixes an issue in 0.22.0 where we passed WriteBuffer to writelines
by mistake, which leads to an error under SSL and uvloop - the
implementation that calls len() on each line of writelines().

Fixes: #700
@Gyllsdorff
Copy link

@fantix

Do you know when the fix for this will be release? Is this a warning log or does it mean that sql commands are failing?

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants