Search code examples
udpsocks

Is there a timeout for UDP in SOCKS5?


I built a SOCKS55 server from the code of https://github.com/postageapp/ss5 recently, and I tried to set this server as a proxy server for audio chat, which is implemented with UDP socket. However, UDP connections dropped out every time I tried to use this proxy server. My UDP ASSOCIATE request is good and works well. Most audio chat apps tested can work normally when proxied by my SOCKS5 server, but they'll be interrupted at about 60s. The log file of this SOCKS5 server only showed me one line: "UDP ASSOCIATE" TERMINATED 0 0 60 (36.157.*.*:36314 -> 119.23.*.*:23333). It seems that there is a timeout setting for UDP conversations of SOCKS5 protocol. Anyone knows anything about it?


Solution

  • SOCKS5 by itself defines no timeout for UDP. But given that UDP has no explicit connection close like TCP, the only way to "close" a UDP connection is to not send any more data. Which means in order to free up the resources held by the SOCKS5 proxy it needs to implement some kind of idle timeout after which the connection gets closed.

    In fact, looking at the source code one can see:

    #define UDP_TIMEOUT     60      /* Seconds */
    

    I cannot find any configuration option to change this timeout so the only way to change it is probably by changing the source code and recompiling.

    Most audio chat apps tested can work normally when proxied by my SOCKS5 server, but they'll be interrupted at about 60s ...

    "UDP ASSOCIATE" TERMINATED 0 0 60 (36.157.*.*:36314 -> 119.23.*.*:23333)
    

    The log message indicates that the UDP association was terminated after 60 seconds without transferring any kind of data - which is explained by the idle timeout of 60 seconds. Given that you did actually transfer audio data within these 60 seconds my guess is that you are using RTP+RTCP (as used in SIP, H.323, XMPP, WebRTC) and that the specific application did transfer audio data over RTP but only allocated the channel for RTCP without ever using it.