Message-ID: From: "james-johnston-thumbtack (@james-johnston-thumbtack)" To: "pgjdbc/pgjdbc" Date: Thu, 16 Jan 2025 10:59:22 +0000 Subject: [pgjdbc/pgjdbc] issue #3481: Support TCP receive window greater than 64K List-Id: X-GitHub-Author-Id: 22308682 X-GitHub-Author-Login: james-johnston-thumbtack X-GitHub-Issue: 3481 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: open X-GitHub-Type: issue X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3481 Content-Type: text/plain; charset=utf-8 The driver offers an option `receiveBufferSize` which sets the `SO_RCVBUF` option via the [setReceiveBufferSize](https://docs.oracle.com/javase/8/docs/api/java/net/Socket.html#setReceiveBufferSize-int-) function. This takes place in the following code chunk: https://github.com/pgjdbc/pgjdbc/blob/032d0e225a91e866d7dae680ebb784507392e803/pgjdbc/src/main/java/org/postgresql/core/v3/ConnectionFactoryImpl.java#L140-L169 However, I note that the call to `setReceiveBufferSize` on line 169 takes place _after_ the `PGStream` connector has already [connected to the PG host](https://github.com/pgjdbc/pgjdbc/blob/032d0e225a91e866d7dae680ebb784507392e803/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L245-L261) on line 140. This carries with it an unfortunate limitation, according to the [setReceiveBufferSize documentation](https://docs.oracle.com/javase/8/docs/api/java/net/Socket.html#setReceiveBufferSize-int-): > The value of [SO_RCVBUF](https://docs.oracle.com/javase/8/docs/api/java/net/SocketOptions.html#SO_RCVBUF) is also used to set the TCP receive window that is advertized to the remote peer. Generally, the window size can be modified at any time when a socket is connected. However, if a receive window larger than 64K is required then this must be requested before the socket is connected to the remote peer. There are two cases to be aware of: > > ... > 2. For client sockets, setReceiveBufferSize() must be called before connecting the socket to its remote peer. This limitation seems to be confirmed in [section 2.1 in RFC-1323](https://datatracker.ietf.org/doc/html/rfc1323#section-2). Therefore, would it make sense to move the call to `setReceiveBufferSize` to be _before_ the connection is made, so that the TCP receive window > 64K can be correctly set?