Mapgax / ibpy

Automatically exported from code.google.com/p/ibpy
Other
0 stars 0 forks source link

Reconnect error: clientId already in use #12

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. app.eConnect()
2. app.eDisconnect()
3. app.eConnect()

What is the expected output? What do you see instead?
I would expect normal connection again, but instead I see this error message:
errorCode:326
    errorMsg:Unable connect as the client id is already in use. Retry with a unique client id.

What version of the product are you using? On what operating system?
0.7.6-9.51 on Windows XP

Please provide any additional information below.

In the IB Gateway I still see that the client is open after eDisconnect is 
called. The other clients (Excel) disconnect properly. If the Python 
interpreter is restarted, the connection is finally closed. 

I inserted an explicit call to socket shutdown and close in eDisconnect to 
force the connection to be broken.

    @eConnect.register(object, Socket, int)
    @synchronized(mlock)
    def eConnect_0(self, socket, clientId):
        self.ibsocket = socket # will use it in eDisconnect
        self.m_dos = DataOutputStream(socket.getOutputStream())
        ...

    @synchronized(mlock)
    def eDisconnect(self):
        ... # omitted
        try:
            if self.reader is not None:
                self.reader.interrupt()
        except (Exception, ), e:
            pass
        try :
            # close the socket, don't wait till the other handle is freed
            #http://stackoverflow.com/questions/409783/socket-shutdown-vs-socket-close
            self.ibsocket.shutdown(SHUT_RDWR)
            self.ibsocket.close()
        except (Exception, ), e:
            pass 
        try:
            if dos is not None:
                dos.close()
        except (Exception, ), e:
            pass 

Best regards,
Aa`Koshh

Original issue reported on code.google.com by aako...@gmail.com on 16 Nov 2011 at 1:03

GoogleCodeExporter commented 8 years ago
This is an excellent solution proposed by Aa'Kossh. It would be great if this 
could be implemented soon

Original comment by NvSolodk...@gmail.com on 21 Sep 2012 at 12:22

GoogleCodeExporter commented 8 years ago
IT would be good if this is implemented soon. The issue still exists in the 
latest version of IbPy and we have manually made the relevant changes to make 
things work. It is better if the same is available as part of the mainline code.

Original comment by ritabr...@gmail.com on 7 Jul 2015 at 11:28