Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting {buffer, Buffer} socket server option #208

Merged
merged 1 commit into from
Dec 18, 2018

Conversation

nickva
Copy link
Collaborator

@nickva nickva commented Dec 13, 2018

If recbuf is undefined then buffer size is set explicitly to the
previous recbuf default of 8192.

The recent option {recbuf, undefined} to allow sockets to pick up optimal OS
default kernel buffer sizes inadvertently reset Erlang's userland buffer size
to a default value of 1460. This buffer size, due to a longstanding bug in
Erlang http parser, limits the maximum URL line that can be parsed by the
{packet, http} socket option, and so breaks existing code.

For example this shows how recbuf also sets buffer size:

> f(), SockInfo = fun(S) -> inet:getopts(S, [recbuf, buffer]) end, {ok, LS} = gen_tcp:listen(0, [{recbuf, 8192}]), LRes = SockInfo(LS).
{ok,[{recbuf,8192},{buffer,8192}]}

Not setting recbuf resets buffer size to 1460:

f(), SockInfo = fun(S) -> inet:getopts(S, [recbuf, buffer]) end, {ok, LS} = gen_tcp:listen(0, []), LRes = SockInfo(LS).
{ok,[{recbuf,131072},{buffer,1460}]}

References:

apache/couchdb#1810
http://erlang.org/pipermail/erlang-questions/2011-June/059571.html
http://erlang.org/doc/man/inet.html#setopts-2

If `recbuf` is `undefined` then buffer size is set explicitly to the
previous `recbuf` default of 8192.

The recent option `{recbuf, undefined}` to allow sockets to pick up optimal OS
default kernel buffer sizes inadvertently reset Erlang's userland buffer size
to a default value of 1460. This buffer size, due to a longstanding bug in
Erlang http parser, limits the maximum URL line that can be parsed by the
{packet, http} socket option, and so breaks existing code.

For example this shows how recbuf also sets buffer size:

```
> f(), SockInfo = fun(S) -> inet:getopts(S, [recbuf, buffer]) end, {ok, LS} = gen_tcp:listen(0, [{recbuf, 8192}]), LRes = SockInfo(LS).
{ok,[{recbuf,8192},{buffer,8192}]}
```

Not setting recbuf resets buffer size to 1460:

```
f(), SockInfo = fun(S) -> inet:getopts(S, [recbuf, buffer]) end, {ok, LS} = gen_tcp:listen(0, []), LRes = SockInfo(LS).
{ok,[{recbuf,131072},{buffer,1460}]}
```

References:

 apache/couchdb#1810
 http://erlang.org/pipermail/erlang-questions/2011-June/059571.html
 http://erlang.org/doc/man/inet.html#setopts-2
@etrepum etrepum merged commit de70122 into mochi:master Dec 18, 2018
@etrepum
Copy link
Member

etrepum commented Dec 18, 2018

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants