[freetds] SO_LINGER options and l_linger value

James K. Lowden jklowden at schemamania.org
Sat Jul 17 18:41:56 EDT 2004


On Fri, 16 Jul 2004 Vlad Lyalikov <vlyalikov at etrade.com> wrote:
> Pardon my ignorance, but I can not figure why FreeTDS sets socket
> options to make abnormal TCP connection termination via RST. 

Thanks for the question.  I'm not well versed in TCP socket programming,
so I had to do some reading to understand what you're saying.  I found:

http://www.kmutt.ac.th/knowledge/programming/c/unix_socket/faq/unix-socket-faq-2.html#ss2.7

AIUI, setting SO_LINGER is a mistake.  We're causing the network layer to
exit abruptly, not giving the server a chance to see our last ACK.  Other
parts of the FAQ definitely discourage using SO_LINGER as well as
SO_KEEPALIVE (which we also use).  It looks to me like we should pull it
out.  

> the change apparently happened on:
> version 1.97, Tue May 13 09:44:58 2003 UTC

I don't find any discussion of TCP options in the ML archive around when
the when Frediano committed 1.97.  

> In particular, RST-driven connection termination generates error
> messages on Sybase server side. Sybase complaints on "client disconnetcs
> ... blah-blah-blah". Or DBA suggests that "client disconnects" errors
> sometimes lead to "timeslice error" + stack trace on Sybase. 

That's bad.  :-(  However, I think it's also a mistake on their part.  A
client can "disconnect" through no fault of its own: the wire might become
unplugged, and no combination of TCP socket options will close the
connection gracefully.  

Naturally, we should still do things right.  

> I checked native OCS 12.0. OCS_12.0 on Solaris does terminate with
> TIME_WAIT states OK.  

A convincing argument, IMO.  

Freddy, do you remember what you were trying to solve?  Does the above
convince you we shouldn't be using SO_LINGER?  

--jkl




More information about the FreeTDS mailing list