userver
userver copied to clipboard
Socket functions do not always honor deadline
Deadline is only checked if a socket would block and some waiting should be performed, however it's completely possible for read/write to go through without blocking.
One could expect that any attempt to do some work after deadline is reached would fail, but as of now it's not the case with Socket
Checking for deadline is not very cheap. Checking it before each socket operation could degrade performance quite a lot.
Are you describing a theoretical problem or the current behavior does harm in some practical case?
or the current behavior does harm in some practical case?
Well, depends on what one would consider 'harmful', but i would argue that the current behavior it not consistent with other parts of the framework: i as developer strongly expect a function that takes deadline as a parameter to be a 'deadline-point', which takes the burden of checking a deadline from me.
Are you describing a theoretical problem ...
Mostly, but i remember being surprised by this when testing clickhouse driver.
Say you have following logic (in pseudocode):
void SendUntilDeadline(deadline) {
while (true) {
some_data = GenerateSomeData();
socket.SendSome(some_data, deadline);
}
}
One could assume that this function stops execution when deadline is reached, but it might go well beyond if receiving side can keep up
I understand that checking deadline before each socket operation is costly, but what's your opinion on checking deadline once as early as possible, before going into while (io_func)
loop?
@apolukhin bump