Skip to content

Commit

Permalink
fix: conev add/del race
Browse files Browse the repository at this point in the history
  • Loading branch information
ruti committed May 4, 2024
1 parent 325d96e commit 1a1bc7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
15 changes: 12 additions & 3 deletions conev.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct poolhd *init_pool(int count)
}
pool->max = count;
pool->count = 0;
pool->init_count = 0;
pool->iters = 0;

#ifndef NOEPOLL
Expand Down Expand Up @@ -51,12 +52,17 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
return 0;
}
val = pool->links[c];
} while (c && val->del_iter == pool->iters);
} while (c < pool->init_count && val->del_iter == pool->iters);

if (c != pool->count) {
struct eval *t = pool->links[c];
pool->links[c] = pool->links[pool->count];
pool->links[pool->count] = t;
}
memset(val, 0, sizeof(*val));

val->fd = fd;
val->index = c;
val->index = pool->count;
val->type = type;

#ifndef NOEPOLL
Expand All @@ -68,14 +74,17 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
}
val->events = ev.events;
#else
struct pollfd *pfd = &(pool->pevents[c]);
struct pollfd *pfd = &(pool->pevents[pool->count]);

pfd->fd = fd;
pfd->events = POLLIN | e;
pfd->revents = 0;
#endif

pool->count++;
if (pool->count > pool->init_count) {
pool->init_count = pool->count;
}
return val;
}

Expand Down
1 change: 1 addition & 0 deletions conev.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct eval {

struct poolhd {
int max;
int init_count;
int count;
int efd;
struct eval **links;
Expand Down
2 changes: 1 addition & 1 deletion proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ int event_loop(int srvfd)
uniperror("(e)poll");
break;
}
LOG(LOG_L, "new event: fd: %d, evt: %s\n", val->fd, eid_name[val->type]);
LOG(LOG_L, "new event: fd: %d, evt: %s, del_iter: %d\n", val->fd, eid_name[val->type], val->del_iter);

if (val->del_iter) {
continue;
Expand Down

0 comments on commit 1a1bc7d

Please sign in to comment.