www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: libssh2_session_free changes nonblock state of already unused fd

libssh2_session_free changes nonblock state of already unused fd

From: Pavel Strashkin <pavel.strashkin_at_gmail.com>
Date: Thu, 27 Oct 2011 17:24:20 -0700

Hello,

Despite the fact that i write here, i don't use libssh2 directly, but
Net::SSH2 (Perl). As most of you knows, Perl has GC which sometimes
doesn't delete an object "right now and right here". There is no
strict order.
What happened to me is that i had one session (socket fd = 3) which
was closed by server side so i handled it and closed everything on my
side (sockets, ...). Net::SSH2 wrapper around the session had not been
deleted yet so libssh2_session_free had not been called either.
After that i created a new one session which had been given with the
same socket fd = 3 as previous one just because previous one is closed
already and the system re-used the number (OS or Perl, don't know).
libssh2 changed nonblock state to TRUE at this point. Most interesting
part had started: when new one session had been successfully initiated
and channel was created, GC made the devil's deal - it called destroy
for previous object which called libssh2_session_free which had set
nonblock for fd = 3 to FALSE. Uppps!

I can't manage the GC work. I don't have cross-references or so on. It
just how script languages works. I think libssh2 should never touch
nonblock state or, at least, should set it to TRUE and forget about it
till the end (i.e. nothing should happen inside libssh2_session_free).
Probably, it should be up to libssh2 user which one IO mode to use -
async or blocking.

Ideas?

Thank you.
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-10-28

the libssh2 team