python-udsoncan icon indicating copy to clipboard operation
python-udsoncan copied to clipboard

SocketConnection cannot be closed

Open nada-ben-ali opened this issue 1 year ago • 6 comments

Closing SocketConnection stucks on self.rxthread.join().

sock: image connector = SocketConnection(sock=sock)

It looks like this issue but for SocketConnection and not IsoTPSocketConnection (for IsoTPSocketConnection there is no stuck) using release 1.22.1 and reproducible with 1.23.0 as well.

By putting the self.sock.settimeout(0.1) back into the SocketConnection constructor, the problem was solved. It was removed when the selector was added in this MR.

nada-ben-ali avatar Mar 28 '24 11:03 nada-ben-ali

There is a unit test that checks that this work. Can you show me how you trigger that issue?

pylessard avatar Apr 01 '24 14:04 pylessard

Is it possible that you call open and close one after the other without waiting? I think there's a weakness in that case

Try to reproduce your error and then try this branch : fix_socket_connection_that_blocks_on_open_close

let me know the outcome

pylessard avatar Apr 01 '24 14:04 pylessard

Problem trigger:

  • sock = socketPool.get(ip, port, connection_name) # socketPool is a pool of open tcp sockets in the test, so it checks if the socket is still open otherwise it creates it if it's closed or if it's a new socket.

  • Create the connector using the returned socket: SocketConnection(sock=sock)

  • create the client by opening the connection using socketConnection.open

  • send a diag after checking that the connection is not closed using SocketConnection.specific_send(payload, timeout=None) --> no problem with sending the diag

  • we've received a positive response

  • it stucks when closing the connection in self.rxthread.join().

I've tested your branch and the same problem still occurs. When opening the connection, self.started_event.is_set() was not True, so it closes the connection and then stucks in self.rxthread.join().

image

nada-ben-ali avatar Apr 03 '24 08:04 nada-ben-ali

Something does not make sense, You say that the the thread never starts but you are able to send and receive.

Are you able to write a demo script that recreate the issue and share that with me? I just don't see how this can happen...

pylessard avatar Apr 03 '24 12:04 pylessard

The thread never starts using the branch you provided with which I was unable to send or receive, it just gets stuck when opening the connection. But without the branch, I'm able to send and receive, but when I close the connection, it stucks.

I will try to make a small script.

nada-ben-ali avatar Apr 03 '24 13:04 nada-ben-ali

Following up on this, update? I still never reproduced your issue. Would need some kind of code that reproduce.

pylessard avatar May 27 '24 11:05 pylessard

If no update, I will close this issue

pylessard avatar Jul 02 '24 19:07 pylessard