[pyOpenSSL] PyEval_RestoreThread: NULL tstate

Martin Sjögren md9ms at mdstud.chalmers.se
Sun Oct 6 12:46:14 CEST 2002


sön 2002-10-06 klockan 12.20 skrev Zoltan Felleg:
> hello list,
> 
> i have a problem with pyOpenSSL, namely as follows:
> i have created a client/server application, where the clients 
> communicate with the servers on a secure channel. When a client tries to 
> log in to a server (ie. after the SSL handshake it tries to send a 
> message), the client dies with the subject, and the server gets a 
> "connection reset by peer" exception. i have two questions about this:
> a.) has anyone seen this before?
> b.) is there an "official" way of handling the WantXYZError exceptions 
> besides ignoring them?

The WantXYZ exceptions are tricky, but that's because it's tricky in
OpenSSL! If you get WantReadError that means OpenSSL wants to read from
the socket but couldn't, so after you've made sure that the socket is
readable, you should call *the same method* again, with *the same
arguments*. It's symmetrical for WantWriteError.

So, if for example you get a WantReadError when you do ssl.write('foo')
you have to wait (using e.g. select) until the socket corresponding to
`ssl' is readable, and then call ssl.write('foo') again. Yes, you can
get WantReadErrors on writing, and WantWriteErrors on reading, since
OpenSSL does handshakes transparently.

> ps: both the client and server are multithreaded, the SSL connection is 
> nonblocking, and the pyOpenSSL version is 0.5.1

If you're running multithreaded, you'd do well to use
OpenSSL.tsafe.Connection instead of OpenSSL.SSL.Connection (tsafe stands
for thread safe :))


Regards,
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Detta ?r en digitalt signerad	meddelandedel
URL: <http://mail.python.org/pipermail/pyopenssl-users/attachments/20021006/b2d3d858/attachment.pgp>


More information about the pyopenssl-users mailing list