Skip to content

Commit e51a98d

Browse files
committed
monitoring list fix
1 parent b0dd8d0 commit e51a98d

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

src/core/http_parse_mon.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ void monitoring_add(scache_connection* conn){
281281

282282
// Add connection to the monitoring linked list
283283
if(mon_tail == NULL){
284+
assert(mon_head == NULL);
284285
mon_tail = mon_head = conn;
285286
}else{
286287
// insert at tail
@@ -295,21 +296,29 @@ void monitoring_destroy(scache_connection* connection){
295296
assert(connection->ltype == mon_listener);
296297
scache_connection* t;
297298

299+
if(mon_head == connection){
300+
assert(connection->monitoring.prev == NULL);
301+
mon_head = connection->monitoring.next;
302+
}
303+
304+
if(mon_tail == connection){
305+
assert(connection->monitoring.next == NULL);
306+
mon_tail = connection->monitoring.prev;
307+
if(mon_head == NULL){
308+
assert(connection->monitoring.prev == NULL);
309+
// early exit we remvoed from both ends
310+
return;
311+
}
312+
}
313+
314+
298315
/*
299316
head ... | connection | t | ... tail
300317
*/
301318
t = connection->monitoring.next;
302319
if(t != NULL){
303320
assert(t->monitoring.prev == connection);
304321
t->monitoring.prev = connection->monitoring.prev;
305-
if(t->monitoring.prev == NULL && mon_head == connection) {
306-
assert(mon_head == connection);
307-
mon_head = t;
308-
}
309-
}else if(mon_tail == connection){
310-
// Only if we are destroying the tail t will be NULL
311-
assert(connection == mon_tail);
312-
mon_tail = t;
313322
}
314323

315324
/*
@@ -319,13 +328,6 @@ void monitoring_destroy(scache_connection* connection){
319328
if(t != NULL){
320329
assert(t->monitoring.next == connection);
321330
t->monitoring.next = connection->monitoring.next;
322-
if(t->monitoring.next == NULL && mon_tail == connection) {
323-
assert(mon_tail == connection);
324-
mon_tail = t;
325-
}
326-
}else if(mon_head == connection){
327-
// Only if we are destroying the head will t be null
328-
mon_head = t;
329331
}
330332
}
331333

@@ -379,7 +381,7 @@ void monitoring_check(){
379381
mon_tail = conn;
380382
}else{
381383
mon_tail = mon_head = conn;
382-
conn->monitoring.next = conn->monitoring.prev = NULL;
384+
conn->monitoring.prev = NULL;
383385
}
384386
conn->monitoring.next = NULL;
385387

0 commit comments

Comments
 (0)