Fixed some license server hangups
This commit is contained in:
parent
cd8e2974f2
commit
f3441e0115
@ -134,13 +134,14 @@ void LicenseServer::handleEventWrite(int fd, short, void* ptrServer) {
|
|||||||
if(!client) return;
|
if(!client) return;
|
||||||
|
|
||||||
buffer::RawBuffer* write_buffer{nullptr};
|
buffer::RawBuffer* write_buffer{nullptr};
|
||||||
|
std::unique_lock write_lock(client->network.write_queue_lock);
|
||||||
while(true) { //TODO: May add some kind of timeout?
|
while(true) { //TODO: May add some kind of timeout?
|
||||||
std::lock_guard lock(client->network.write_queue_lock);
|
|
||||||
write_buffer = TAILQ_FIRST(&client->network.write_queue);
|
write_buffer = TAILQ_FIRST(&client->network.write_queue);
|
||||||
if(!write_buffer) return;
|
if(!write_buffer) return;
|
||||||
|
|
||||||
auto writtenBytes = send(fd, &write_buffer->buffer[write_buffer->index], write_buffer->length - write_buffer->index, 0);
|
auto writtenBytes = send(fd, &write_buffer->buffer[write_buffer->index], write_buffer->length - write_buffer->index, 0);
|
||||||
if(writtenBytes <= 0) {
|
if(writtenBytes <= 0) {
|
||||||
|
write_lock.unlock();
|
||||||
if(writtenBytes == -1 && errno == EAGAIN)
|
if(writtenBytes == -1 && errno == EAGAIN)
|
||||||
return;
|
return;
|
||||||
logError(LOG_LICENSE_CONTROLL, "Invalid write. Disconnecting remote client. Message: {}/{}", errno, strerror(errno));
|
logError(LOG_LICENSE_CONTROLL, "Invalid write. Disconnecting remote client. Message: {}/{}", errno, strerror(errno));
|
||||||
|
@ -297,17 +297,21 @@ void WebStatistics::handleEventWrite(int file_descriptor, short, void* ptr_serve
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::lock_guard<std::recursive_mutex> lock(client->execute_lock);
|
std::unique_lock elock(client->execute_lock);
|
||||||
if(client->buffer_write.empty()) return;
|
if(client->buffer_write.empty()) return;
|
||||||
auto& buffer = client->buffer_write.front();
|
auto& buffer = client->buffer_write.front();
|
||||||
|
|
||||||
auto written = send(file_descriptor, buffer.data(), buffer.length(), MSG_DONTWAIT | MSG_NOSIGNAL);
|
auto written = send(file_descriptor, buffer.data(), buffer.length(), MSG_DONTWAIT | MSG_NOSIGNAL);
|
||||||
if(written < 0){
|
if(written < 0){
|
||||||
|
elock.unlock();
|
||||||
|
|
||||||
if(errno == EWOULDBLOCK) return;
|
if(errno == EWOULDBLOCK) return;
|
||||||
logError(LOG_LICENSE_WEB, "[{}] Invalid write: {}/{}. Closing connection.", client->client_prefix(), errno, strerror(errno));
|
logError(LOG_LICENSE_WEB, "[{}] Invalid write: {}/{}. Closing connection.", client->client_prefix(), errno, strerror(errno));
|
||||||
server->close_connection(client);
|
server->close_connection(client);
|
||||||
return;
|
return;
|
||||||
} else if(written == 0) {
|
} else if(written == 0) {
|
||||||
|
elock.unlock();
|
||||||
|
|
||||||
logError(LOG_LICENSE_WEB, "[{}] Invalid write (eof). Closing connection", client->client_prefix());
|
logError(LOG_LICENSE_WEB, "[{}] Invalid write (eof). Closing connection", client->client_prefix());
|
||||||
server->close_connection(client);
|
server->close_connection(client);
|
||||||
return;
|
return;
|
||||||
@ -334,17 +338,20 @@ void WebStatistics::close_connection(const std::shared_ptr<license::web::WebStat
|
|||||||
else; //TODO Error handling?
|
else; //TODO Error handling?
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::recursive_mutex> lock(client->execute_lock);
|
std::unique_lock elock(client->execute_lock);
|
||||||
if(client->event_read) {
|
auto event_read = std::exchange(client->event_read, nullptr);
|
||||||
event_del(client->event_read);
|
auto event_write = std::exchange(client->event_write, nullptr);
|
||||||
event_free(client->event_read);
|
elock.unlock();
|
||||||
client->event_read = nullptr;
|
if(event_read) {
|
||||||
|
event_del(event_read);
|
||||||
|
event_free(event_read);
|
||||||
}
|
}
|
||||||
if(client->event_write) {
|
if(event_write) {
|
||||||
event_del(client->event_write);
|
event_del(event_write);
|
||||||
event_free(client->event_write);
|
event_free(event_write);
|
||||||
client->event_write = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elock.lock();
|
||||||
if(client->file_descriptor > 0) {
|
if(client->file_descriptor > 0) {
|
||||||
if(shutdown(client->file_descriptor, SHUT_RDWR) < 0); //TODO error handling
|
if(shutdown(client->file_descriptor, SHUT_RDWR) < 0); //TODO error handling
|
||||||
if(close(client->file_descriptor) < 0); //TODO error handling
|
if(close(client->file_descriptor) < 0); //TODO error handling
|
||||||
@ -353,6 +360,7 @@ void WebStatistics::close_connection(const std::shared_ptr<license::web::WebStat
|
|||||||
|
|
||||||
if(client->pipe_websocket)
|
if(client->pipe_websocket)
|
||||||
client->pipe_websocket = nullptr;
|
client->pipe_websocket = nullptr;
|
||||||
|
|
||||||
if(client->pipe_ssl) {
|
if(client->pipe_ssl) {
|
||||||
client->pipe_ssl->finalize();
|
client->pipe_ssl->finalize();
|
||||||
client->pipe_ssl = nullptr;
|
client->pipe_ssl = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user