gnzsnz / ib-gateway-docker

Docker image with IB Gateway/TWS and IBC
https://github.com/users/gnzsnz/packages/container/package/ib-gateway
MIT License
280 stars 54 forks source link

Usage of socat during container restart #173

Closed marcel-o closed 1 month ago

marcel-o commented 2 months ago

Is your feature request related to a problem? Please describe

There seems to be an issue with the IB Gateway container during daily restart, once the container is restarted, socat starts port forwarding but fails to bind the address because it's already in use

2024-09-23 23:45:02.156 socat[15] E bind(5, {AF=2 0.0.0.0:4004}, 16): Address already in use 2024-09-23 23:45:02.150 .> Starting socat 2024-09-23 23:45:02.148 .> SOCAT_PORT set to: 4004

Describe the solution you'd like

Looking at stable/scripts/run_socat.sh Was thinking if this line could be the reason the issue happens: socat TCP-LISTEN:"${PUBLISHED_PORT}",fork TCP:127.0.0.1:"${LOCAL_PORT}"

Could this be a possible solution for allowing the address to be reused even if the port is still in a TIME_WAIT state? socat TCP-LISTEN:"${PUBLISHED_PORT}",fork,reuseaddr TCP:TCP:127.0.0.1:"${LOCAL_PORT}

https://stackoverflow.com/questions/75059280/what-actually-reuseaddr-option-does-in-socat

gnzsnz commented 2 months ago

thanks for sharing this

2024-09-20T19:47:33.112238+02:00 localhost docker/quant-tws-1[115320]: 2024/09/20 19:47:33 socat[816] E connect(5, AF=2 127.0.0.1:7497, 16): Connection refused
2024-09-21T04:20:01.683586+02:00 localhost docker/quant-tws-1[115320]: 2024/09/21 04:20:01 socat[25989] E connect(5, AF=2 127.0.0.1:7497, 16): Connection refused
2024-09-21T04:20:06.395181+02:00 localhost docker/quant-tws-1[115320]: 2024/09/21 04:20:06 socat[26158] E connect(5, AF=2 127.0.0.1:7497, 16): Connection refused
2024-09-21T04:20:11.579297+02:00 localhost docker/quant-tws-1[115320]: 2024/09/21 04:20:11 socat[26433] E connect(5, AF=2 127.0.0.1:7497, 16): Connection refused
2024-09-21T04:20:18.312081+02:00 localhost docker/quant-tws-1[115320]: 2024/09/21 04:20:18 socat[26448] E connect(5, AF=2 127.0.0.1:7497, 16): Connection refused
2024-09-21T04:20:24.678921+02:00 localhost docker/quant-tws-1[115320]: 2024/09/21 04:20:24 socat[26594] E connect(5, AF=2 127.0.0.1:7497, 16): Connection refused

I do have a warning during daily restart, because my code tries to reconnect. But that's not a problem, once ibgateway/TWS is up and running socat keeps working without any issue.

in your error it's referring to the external port {AF=2 0.0.0.0:4004} please check that 4004 is free. So it seems that you are having a problem with the external port not being available.

gnzsnz commented 1 month ago

closed due to lack of activity. this does not seems to be a bug, if needed please continue in discussion section.