This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 'Cannot serialize socket object' after ssl.wrap_socket
Type: Stage: resolved
Components: SSL Versions: Python 3.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: Anderseta, christian.heimes, pitrou
Priority: normal Keywords:

Created on 2017-07-02 23:23 by Anderseta, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg297526 - (view) Author: Anderson (Anderseta) Date: 2017-07-02 23:23
---------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/socketserver.py", line 317, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/opt/storage_server/server_tcp.py", line 121, in process_request
    self.pipes[self.proc_turn][1].send((request, client_address))
  File "/usr/local/lib/python3.6/multiprocessing/connection.py", line 206, in send
    self._send_bytes(_ForkingPickler.dumps(obj))
  File "/usr/local/lib/python3.6/multiprocessing/reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
  File "/usr/local/lib/python3.6/socket.py", line 185, in __getstate__
    raise TypeError("Cannot serialize socket object")
TypeError: Cannot serialize socket object
---------------------------------------

I am trying to send a ssl wrapped socket object (server side) into a pipe to another process using multiprocessing.

Btw, without ssl_wrap it works.

Basically this:

newsocket, fromaddr = self.socket.accept()

connstream = ssl.wrap_socket(newsocket, server_side=True, certfile=self.certfile, keyfile=self.keyfile)

pipe = multiprocessing.Pipe()
proc = multiprocessing.Process(target=proc_run, args=(pipe[0],), daemon=False)
proc.start()

#Error here
pipe[1].send((connstream, fromaddr))

I am sorry if this is intentional.
msg297536 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-07-03 07:53
It is simply not possible to serialize the state of a SSL socket.
(theoretically it should be possible, but AFAIK OpenSSL offers no API for it).
History
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 75012
2017-07-03 07:53:59pitrousetstatus: open -> closed
resolution: wont fix
stage: resolved
2017-07-03 07:53:47pitrousetnosy: + pitrou
messages: + msg297536
2017-07-02 23:27:07Andersetasettitle: 'Cannot serialize socket object' after ssl_wrap -> 'Cannot serialize socket object' after ssl.wrap_socket
2017-07-02 23:23:29Andersetacreate