pyuv icon indicating copy to clipboard operation
pyuv copied to clipboard

No buffer available on Windows platform

Open vit1251 opened this issue 9 years ago • 7 comments

Minimal crash code:

#!/usr/bin/python

import sys

import pyuv

##
## Default loop
##

loop = pyuv.Loop.default_loop()


##
## Create TCP connection
##

# One of FreeNODE IRC Server Host
ip, port = '62.231.75.133', 6666

def read_cb(tcp_handle, data, errno):
    print("Socket read (errno = {errno!r})".format(errno=errno))
    print data

def connect_cb(tcp_handle, errno):
    print("Connect (errno = {errno!r})".format(errno=errno))
    tcp_handle.start_read(read_cb)

tcp = pyuv.TCP(loop)
tcp.connect((ip, port), connect_cb)

##
## Using TTY interaction
##

def terminal_read_cb(*args):
    print("Terminal read")
    print args

tty = pyuv.TTY(loop, sys.stdin.fileno(), True)
tty.start_read(terminal_read_cb)


##
## Main point
##

loop.run()

On Windows platform it cause a

Connect (errno = None)
Socket read (errno = -4060)
None
Terminal read
Unhandled exception in callback

vit1251 avatar Jan 05 '16 01:01 vit1251

Do you have a pyuv-only test case which exhibits the problem? Without that or a traceback there is little I can do :-S

saghul avatar Jan 05 '16 08:01 saghul

I am not sure but I saw somewhere that on Windows libuv may need more then one buffer at same time. I think this number is equal to number of threads that uses by iocp. But pyuv uses only one buffer all the time. (https://github.com/saghul/pyuv/blob/94d34d6522bf079577427f93e2e107be905dd9f2/src/common.c#L267)

moteus avatar Jan 05 '16 08:01 moteus

@moteus libuv uses a single thread (per loop) for IOCP. Within a loop operations will always be like alloc -> read, alloc -> read, so using a single buffer per loop is safe as far as I'm concerned.

saghul avatar Jan 05 '16 09:01 saghul

What happens if you ignore pyuv.errno.UV_ENOBUFS on the read callback? Does it continue working properly?

saghul avatar Jan 06 '16 07:01 saghul

What happens if you ignore pyuv.errno.UV_ENOBUFS on the read callback?

If it mean just ignore this error (does not raise and handle this problem) then as you can see simple source code may continue but it look like it freeze.

What do you mean say "if you ignore pyuv.errno.UV_ENOBUFS on the read callback"? I was not invoke additional function for ignore this error or doing hidden setup somewhere. You see full source code there.

Does it continue working properly?

No. No more socket read callback. But TTY was working. I redesign code and try start socket after tty initialize and also have buffer error.

vit1251 avatar Jan 06 '16 21:01 vit1251

Hum, that's weird. I'll take a look on a Windows machine as soon as I can.

saghul avatar Jan 06 '16 23:01 saghul

@vit1251 Is this issue still present on pyuv 1.3.0? If yes, please provide a test case which is not requiring internet access. I modified your script above connecting to a local TCP server and cannot reproduce this issue. Which Python version are you using?

schlamar avatar May 31 '17 08:05 schlamar