Bug 196061 - setsockopt(s,IPPROTO_TCP,TCP_NODELAY,...) returns -1 && errno == 0
Summary: setsockopt(s,IPPROTO_TCP,TCP_NODELAY,...) returns -1 && errno == 0
Status: Closed Overcome By Events
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.0-RELEASE
Hardware: amd64 Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2014-12-17 13:45 UTC by Warren Gay
Modified: 2020-09-12 08:18 UTC (History)
2 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Warren Gay 2014-12-17 13:45:53 UTC
setsockopt(s,IPPROTO_TCP,TCP_NODELAY,...) returns -1 as if it has failed, but errno == 0. This occurs on an IPv4 socket, newly accepted by:


It appears that the setsockopt() call has succeeded because there seems to be some improvement in the http server performance after the call.
Comment 1 Marián Černý 2015-11-24 09:53:38 UTC
This is probably not be related.

On FreeBSD 9.3 it returns -1 and errno=22 (EINVAL) for me in passenger:

Ser/Server.h:655: [ApiServer] Cannot disable Nagle's algorithm on a TCP socket: Invalid argument (errno=22)

    if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)) == -1
     && errno != ENOPROTOOPT
     && errno != ENOTSUP
     && errno != EXTENSION_EOPNOTSUPP)
        int e = errno;
        SKS_WARN("Cannot disable Nagle's algorithm on a TCP socket: " <<
            strerror(e) << " (errno=" << e << ")");
Comment 2 Michael Tuexen freebsd_committer 2020-09-12 07:58:14 UTC
(In reply to Marián Černý from comment #1)
If fd is not a TCP socket, but a UNIX domain socket, this is expected behaviour. Since the code handles TCP and UNIX domain sockets, I guess this is what happens. If I'm wrong and this still happens on a FreeBSD version, which is supported, please reopen the issue.
Comment 3 Michael Tuexen freebsd_committer 2020-09-12 08:18:52 UTC
(In reply to Warren Gay from comment #0)
I don't see a way of indicating an error and having disabled the Nagle algorithm. I would like to see the application code. I'm closing this, since this report is for a FreeBSD version, which is not supported anymore. If the problem persists on a supported version, please reopen and I'll be happy to debug the issue.