mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Merge pull request #61309 from ClickHouse/chesema-fix-poco-tcp-server
fix data race in poco tcp server
This commit is contained in:
commit
689c715408
@ -93,7 +93,7 @@ void TCPServerDispatcher::release()
|
|||||||
|
|
||||||
void TCPServerDispatcher::run()
|
void TCPServerDispatcher::run()
|
||||||
{
|
{
|
||||||
AutoPtr<TCPServerDispatcher> guard(this, true); // ensure object stays alive
|
AutoPtr<TCPServerDispatcher> guard(this); // ensure object stays alive
|
||||||
|
|
||||||
int idleTime = (int) _pParams->getThreadIdleTime().totalMilliseconds();
|
int idleTime = (int) _pParams->getThreadIdleTime().totalMilliseconds();
|
||||||
|
|
||||||
@ -149,11 +149,13 @@ void TCPServerDispatcher::enqueue(const StreamSocket& socket)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
this->duplicate();
|
||||||
_threadPool.startWithPriority(_pParams->getThreadPriority(), *this, threadName);
|
_threadPool.startWithPriority(_pParams->getThreadPriority(), *this, threadName);
|
||||||
++_currentThreads;
|
++_currentThreads;
|
||||||
}
|
}
|
||||||
catch (Poco::Exception& exc)
|
catch (Poco::Exception& exc)
|
||||||
{
|
{
|
||||||
|
this->release();
|
||||||
++_refusedConnections;
|
++_refusedConnections;
|
||||||
std::cerr << "Got exception while starting thread for connection. Error code: "
|
std::cerr << "Got exception while starting thread for connection. Error code: "
|
||||||
<< exc.code() << ", message: '" << exc.displayText() << "'" << std::endl;
|
<< exc.code() << ", message: '" << exc.displayText() << "'" << std::endl;
|
||||||
|
@ -123,17 +123,15 @@ protected:
|
|||||||
|
|
||||||
std::string getServerUrl() const
|
std::string getServerUrl() const
|
||||||
{
|
{
|
||||||
return "http://" + server_data.socket->address().toString();
|
return "http://" + server_data.server->socket().address().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void startServer()
|
void startServer()
|
||||||
{
|
{
|
||||||
server_data.reset();
|
server_data.reset();
|
||||||
server_data.params = new Poco::Net::HTTPServerParams();
|
|
||||||
server_data.socket = std::make_unique<Poco::Net::ServerSocket>(server_data.port);
|
|
||||||
server_data.handler_factory = new HTTPRequestHandlerFactory(slowdown_receive);
|
server_data.handler_factory = new HTTPRequestHandlerFactory(slowdown_receive);
|
||||||
server_data.server = std::make_unique<Poco::Net::HTTPServer>(
|
server_data.server = std::make_unique<Poco::Net::HTTPServer>(
|
||||||
server_data.handler_factory, *server_data.socket, server_data.params);
|
server_data.handler_factory, server_data.port);
|
||||||
|
|
||||||
server_data.server->start();
|
server_data.server->start();
|
||||||
}
|
}
|
||||||
@ -155,8 +153,7 @@ protected:
|
|||||||
{
|
{
|
||||||
// just some port to avoid collisions with others tests
|
// just some port to avoid collisions with others tests
|
||||||
UInt16 port = 9871;
|
UInt16 port = 9871;
|
||||||
Poco::Net::HTTPServerParams::Ptr params;
|
|
||||||
std::unique_ptr<Poco::Net::ServerSocket> socket;
|
|
||||||
HTTPRequestHandlerFactory::Ptr handler_factory;
|
HTTPRequestHandlerFactory::Ptr handler_factory;
|
||||||
std::unique_ptr<Poco::Net::HTTPServer> server;
|
std::unique_ptr<Poco::Net::HTTPServer> server;
|
||||||
|
|
||||||
@ -171,8 +168,6 @@ protected:
|
|||||||
|
|
||||||
server = nullptr;
|
server = nullptr;
|
||||||
handler_factory = nullptr;
|
handler_factory = nullptr;
|
||||||
socket = nullptr;
|
|
||||||
params = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~ServerData() {
|
~ServerData() {
|
||||||
|
Loading…
Reference in New Issue
Block a user