sourcey / libsourcey

C++14 evented IO libraries for high performance networking and media based applications
https://sourcey.com/libsourcey
GNU Lesser General Public License v2.1
1.31k stars 347 forks source link

https sample code get segfault #221

Open seawolf0820 opened 6 years ago

seawolf0820 commented 6 years ago

Hi! I'm trying to setup a https server with libsourcey, but I got a segfault with the sample code:

`net::SSLManager::initNoVerifyServer();

http::Server srv(address, std::make_shared( net::SSLManager::instance().defaultServerContext())); srv.start();

srv.Connection += [](http::ServerConnection::Ptr conn) { conn->send("hello universe", 14); conn->close(); };

std::cout << "HTTPS server listening on " << address << std::endl; waitForShutdown(); finnaly I found the problem seems to be caused by conn->close(); This code works well: http::Server srv(address, std::make_shared( net::SSLManager::instance().defaultServerContext())); srv.start();

srv.Connection += [](http::ServerConnection::Ptr conn) {
    conn->response().add("Content-Length", "14");
    conn->response().add("Connection", "close");
    conn->sendHeader();
    conn->send("hello universe", 14);
};`
seawolf0820 commented 6 years ago

I think I found something about this issue: in http/src/server.cpp:122:

 for (auto it = _connections.begin(); it != _connections.end(); ++it) {
        if (it->get() == &conn) {
            _connections.erase(it);
            return;
        }

after _connections.erase(it);, SSLSocket::~SSLSocket will be called. but we are still in a scy::net::SSLSocket::onRead call. After adding deleteLater(*it) before this line, the segfault is gone. but I get this warning from curl:

curl: (56) GnuTLS recv error (-110): The TLS connection was non-properly terminated.