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

tcp::no_delay leads to Bad file descriptor #812

Open
kpeeters opened this issue Apr 20, 2019 · 6 comments
Open

tcp::no_delay leads to Bad file descriptor #812

kpeeters opened this issue Apr 20, 2019 · 6 comments
Labels
0.9.x Asio Transport Fixed Issue is fixed but not yet released

Comments

@kpeeters
Copy link

The following program attempts to start a server and set the NO_DELAY option on the socket as soon as it has been initialised. This worked with 0.7, but no longer with 0.8.1. Commenting out the s.set_option(option) line makes it work again.

Am I doing this wrong or is this a bug?

#include <websocketpp/server.hpp>
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/common/functional.hpp>

typedef websocketpp::server<websocketpp::config::asio> WebsocketServer;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;

void on_socket_init(websocketpp::connection_hdl, boost::asio::ip::tcp::socket & s)
	{
	boost::asio::ip::tcp::no_delay option(true);
	s.set_option(option);
	}

int main(int, char **)
	{
	WebsocketServer wserver;

	wserver.init_asio();
	wserver.set_reuse_addr(true);
	wserver.set_socket_init_handler(bind(&on_socket_init, ::_1,::_2));
	wserver.listen(0);
	wserver.start_accept();

	websocketpp::lib::asio::error_code ec;
	auto p = wserver.get_local_endpoint(ec);
	std::cout << p.port()  << std::endl;
	}
@jzablot
Copy link

jzablot commented Jun 7, 2019

I am seeing this issue as well. Was working on websocketpp 0.5.1; upgraded to 0.8.1 and it no longer works

@mrakh
Copy link

mrakh commented Oct 3, 2019

I am also experiencing the same issue. My application works without errors when using v0.7.0. When I try to use v0.8.1 instead, I get the error. Commenting out the tcp::no_delay line in my code makes it work, but I would like to set the option. Attached is the relevant gdb stack trace, if that's any help:

#0  0x00007ffff66eae97 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ffff66ec801 in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007ffff6d41957 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff6d47ab6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff6d47af1 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff6d47d24 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00005555555871e0 in asio::detail::throw_exception<std::system_error> (e=...) at /usr/include/asio/detail/throw_exception.hpp:42
#7  0x000055555556cd06 in asio::detail::do_throw_error (err=..., location=0x55555563dd77 "set_option") at /usr/include/asio/detail/impl/throw_error.ipp:49
#8  0x000055555556cc39 in asio::detail::throw_error (err=..., location=0x55555563dd77 "set_option") at /usr/include/asio/detail/throw_error.hpp:41
#9  0x000055555558ee7a in asio::basic_socket<asio::ip::tcp, asio::stream_socket_service<asio::ip::tcp> >::set_option<asio::detail::socket_option::boolean<6, 1> > (this=0x555555918ce0, option=...) at /usr/include/asio/basic_socket.hpp:819

@rambabuwhy
Copy link

Hi
Same here. any solution?
-Thanks

@luoyongh
Copy link

luoyongh commented Aug 7, 2020

Any workaround for this issue?

zaphoyd pushed a commit that referenced this issue Aug 7, 2020
…s like TCP_NODELAY from being set. Improve documentation about how pre_init differs from init_asio. Improve documentation for the TCP pre-bind handler that is the actual solution to the issue this regression related to. references #530 fixes #812
@zaphoyd
Copy link
Owner

zaphoyd commented Aug 7, 2020

This regression from 0.8.0 has been fixed on the develop branch. The socket_init event handler is the correct place to set socket options like TCP_NODELAY on the already accepted socket.

@zaphoyd zaphoyd added Fixed Issue is fixed but not yet released 0.9.x and removed High Priority labels Aug 7, 2020
TwentyPast4 pushed a commit to TroniusGaming/websocketpp that referenced this issue Aug 18, 2022
…s like TCP_NODELAY from being set. Improve documentation about how pre_init differs from init_asio. Improve documentation for the TCP pre-bind handler that is the actual solution to the issue this regression related to. references zaphoyd#530 fixes zaphoyd#812
@sweihub
Copy link

sweihub commented Jan 29, 2024

Hi, why don't you merge the fix into main branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.9.x Asio Transport Fixed Issue is fixed but not yet released
Projects
None yet
Development

No branches or pull requests

7 participants