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

HTTPServerConnection::onServerStopped does not halt poll #3985

Closed
micheleselea opened this issue Mar 23, 2023 · 10 comments
Closed

HTTPServerConnection::onServerStopped does not halt poll #3985

micheleselea opened this issue Mar 23, 2023 · 10 comments
Assignees

Comments

@micheleselea
Copy link
Contributor

micheleselea commented Mar 23, 2023

When you call httpServer->stoppAll(true) we end up in
HTTPServerConnection::onServerStopped -> with abortConnection true
if the http connection is in keepalive waiting for socket().poll(_keepAliveTimeout, Socket::SELECT_READ)
on windows you are waiting for epoll_wait that call GetQueuedCompletionStatusEx
the .close() done in onServerStopped is not enough to exit without waiting for keepalive timeout occur

@micheleselea
Copy link
Contributor Author

I tried a couple of changes but the only way I found rigth now is to change
bool HTTPServerSession::hasMoreRequests()
for doing something like

#if defined(_WIN32 )&&defined(POCO_HAVE_FD_EPOLL)
		Poco::Timestamp tsKeepAlive;
		do {
			if (!connected()) return false;
			if ((buffered() > 0) || socket().poll(Poco::Timespan(0, 250000), Socket::SELECT_READ)) return true;
		} while (!tsKeepAlive.isElapsed(_keepAliveTimeout.totalMicroseconds()));
		return false;
#else
		return (buffered() > 0) || socket().poll(_keepAliveTimeout, Socket::SELECT_READ);
#endif

@micheleselea micheleselea changed the title HTTPServerConnection::onServerStopped HTTPServerConnection::onServerStopped slow Mar 23, 2023
@micheleselea micheleselea changed the title HTTPServerConnection::onServerStopped slow HTTPServerConnection::onServerStopped does not halt poll Mar 23, 2023
@micheleselea
Copy link
Contributor Author

An alternative way to handle that is to do this
piscisaureus/wepoll#20

@micheleselea
Copy link
Contributor Author

I think that this function
PostQueuedCompletionStatus(_epollfd, 0, 0, NULL);
can work in PollSet too instead using a tcp listening connection

@lovelycheep
Copy link

i had the same problem with version 1.10.1.

Here is the crash stack:

image

I tried to simulate the stack, but the position was never right.
image

Does anyone know how to analyze and solve this problem

@micheleselea
Copy link
Contributor Author

@lovelycheep I think the best solution is to do
piscisaureus/wepoll#20
so cheanging PollSet wakeUp like this
so you can avoid creating _eventfd

	void wakeUp()
	{		
#ifdef WEPOLL_H_
		if (_port > 0) {
			StreamSocket ss(SocketAddress("127.0.0.1", _port));
		}
		else if (_epollfd > 0) {
			PostQueuedCompletionStatus(_epollfd, 0, 0, NULL);
		}
#else
		uint64_t val = 1;
		// This is guaranteed to write into a valid fd,
		// or 0 (meaning PollSet is being destroyed).
		// Errors are ignored.
		write(_eventfd, &val, sizeof(val));
#endif
	}

@aleks-f
Copy link
Member

aleks-f commented Oct 23, 2023

This is likely addressed by this fix

But, generally speaking, code that is reproducing the issue is the best way to report and get it fixed - create a test case that fails send a pull.

@aleks-f aleks-f removed this from the Release 1.12.5 milestone Oct 23, 2023
@aleks-f
Copy link
Member

aleks-f commented Oct 23, 2023

I think that this function PostQueuedCompletionStatus(_epollfd, 0, 0, NULL); can work in PollSet too instead using a tcp listening connection

it doesn't

testPollSetWakeUp:
Net\testsuite\binA64\TestSuited.exe (process 15108) exited with code -1073741819.

@micheleselea
Copy link
Contributor Author

I managed to work the PostQueuedCompletionStatus working, so no problem, I already fix my code, if you think is not the correct way to handle it, never mind

@vm2mv
Copy link
Contributor

vm2mv commented Jan 9, 2024

@aleks-f, are you planning to fix this problem?
I'm forced to use POCO without POCO_HAVE_FD_EPOLL now, but I don't like this option.

@aleks-f
Copy link
Member

aleks-f commented Jan 10, 2024

@vm2mv the solution proposed here was segfaulting when I tried it.

Generally speaking, "here's a fix from my heavily tweaked poco code" is not an efficient way to get the issues fixed. If you have a problem and want it fixed quick, send a pull request to devel branch, let's see if CI goes green with it and then we'll be in a much better place to fix it.

/cc @matejk

@matejk matejk mentioned this issue Mar 4, 2024
10 tasks
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

No branches or pull requests

4 participants