pulse-server: handle out-of-files better

When we don't have enough files to accept the connection, clear the
_IN flag so that we don't try to accept if over and over again.
When a client disconnects, set the flag again so that we try to
accecpt new connections again.

See #1305
This commit is contained in:
Wim Taymans 2021-06-18 15:22:10 +02:00
parent 22b5b6b120
commit def0caf281
2 changed files with 22 additions and 4 deletions

View file

@ -5350,14 +5350,22 @@ static int client_free_stream(void *item, void *data)
*/
static bool client_detach(struct client *client)
{
if (client->server == NULL)
struct impl *impl = client->impl;
struct server *server = client->server;
if (server == NULL)
return false;
pw_log_info(NAME" %p: client %p detaching", client->server, client);
pw_log_info(NAME" %p: client %p detaching", server, client);
/* remove from the `server->clients` list */
spa_list_remove(&client->link);
client->server->n_clients--;
server->n_clients--;
if (server->wait_clients > 0 && --server->wait_clients == 0) {
int mask = server->source->mask;
SPA_FLAG_SET(mask, SPA_IO_IN);
pw_loop_update_io(impl->loop, server->source, mask);
}
client->server = NULL;
return true;
@ -5777,8 +5785,17 @@ on_connect(void *data, int fd, uint32_t mask)
length = sizeof(name);
client_fd = accept4(fd, (struct sockaddr *) &name, &length, SOCK_CLOEXEC);
if (client_fd < 0)
if (client_fd < 0) {
if (errno == EMFILE || errno == ENFILE) {
if (server->n_clients > 0) {
int mask = server->source->mask;
SPA_FLAG_CLEAR(mask, SPA_IO_IN);
pw_loop_update_io(impl->loop, server->source, mask);
server->wait_clients++;
}
}
goto error;
}
if (server->n_clients >= MAX_CLIENTS) {
close(client_fd);