Skip to content

Commit 2fb5bdd

Browse files
committed
monitoring (4)
1 parent 6b367b9 commit 2fb5bdd

4 files changed

Lines changed: 56 additions & 10 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,26 @@ jobs:
2727
valgrind --leak-check=full ./tests/${{ matrix.release }}/tests $PWD/src/server/${{ matrix.release }}/scache $PWD/testcases/
2828
- name: Spam test
2929
run: |
30-
echo "todo"
30+
echo "todo"
31+
- name: Valgrind monitoring test
32+
run: |
33+
sudo mkdir -p /var/lib/scache/ &
34+
sudo apt-get install psmisc
35+
wait
36+
sudo chmod 0777 /var/lib/scache/ -R
37+
38+
function query {
39+
sleep 2
40+
for i in {1..50}
41+
do
42+
curl 127.0.0.1:8082/conn &
43+
done
44+
45+
sleep 110
46+
47+
killall curl
48+
}
49+
50+
query &
51+
52+
timeout 2m valgrind --leak-check=full --show-leak-kinds=all src/server/${{ matrix.release }}/scache -B 127.0.0.1:8082

src/core/connection.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@ static scache_connection* connection_get(int fd) {
282282
}
283283

284284
bool connection_remove(int fd) {
285+
scache_connection_node* node;
285286
scache_connection_node* temp = NULL;
286-
scache_connection_node* node = &ctable[CONNECTION_HASH_KEY(fd)];
287+
assert(fd >= 0);
288+
node = &ctable[CONNECTION_HASH_KEY(fd)];
287289
if (node->connection.client_sock == -1) {
288290
WARN("Unable to find fd: %d connection entry to remove", fd);
289291
return false;
@@ -639,12 +641,14 @@ On close connection cleanup routine
639641
*/
640642
void connection_cleanup_http(scache_connection_node* connection, bool toFree = false) {
641643
assert(connection != NULL);
644+
int fd;
642645

643646
//Close socket to client
644647
if (connection->connection.client_sock != -1) {
645648
http_cleanup(&connection->connection);
646-
close(connection->connection.client_sock);
649+
fd = connection->connection.client_sock;
647650
connection->connection.client_sock = -1;
651+
close(fd);
648652
}
649653

650654
//Handle chained connections

src/core/db.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,12 @@ static bool db_load_from_save(){
694694
close_fd:
695695
fclose(fp);
696696
close_fd2:
697-
close(db.fd_blockfile);
697+
if(fp == NULL) close(fd);
698+
699+
fd = db.fd_blockfile;
698700
db.fd_blockfile = -1;
701+
close(fd);
699702

700-
if(fp == NULL) close(fd);
701703

702704
return ret;
703705
}

src/core/http_parse_mon.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ state_action http_respond_writecount_starting(scache_connection* connection) {
7878
static state_action http_respond_start_to_count(scache_connection* connection) {
7979
DEBUG("[#%d] Ready to start to count \n", connection->client_sock);
8080
monitoring_add(connection);
81-
return http_respond_cleanupafterwrite(connection);
81+
CONNECTION_HANDLER(connection, http_respond_cleanupafterwrite);
82+
return continue_processing;
8283
}
8384

8485
state_action http_mon_read_eol_inital(scache_connection* connection, char* buffer, int n, uint32_t& temporary) {
@@ -275,6 +276,7 @@ void monitoring_add(scache_connection* conn){
275276
if(mon_tail == NULL){
276277
mon_tail = mon_head = conn;
277278
}else{
279+
// insert at tail
278280
assert(mon_tail->monitoring.next == NULL);
279281
mon_tail->monitoring.next = conn;
280282
conn->monitoring.prev = mon_tail;
@@ -286,26 +288,41 @@ void monitoring_destroy(scache_connection* connection){
286288
assert(connection->ltype == mon_listener);
287289
scache_connection* t;
288290

291+
/*
292+
head ... | connection | t | ... tail
293+
*/
289294
t = connection->monitoring.next;
290295
if(t != NULL){
291296
assert(t->monitoring.prev == connection);
292297
t->monitoring.prev = connection->monitoring.prev;
293298
if(t->monitoring.prev == NULL) {
294-
assert(mon_tail == connection);
295-
mon_tail = t;
299+
assert(mon_head == connection);
300+
mon_head = t;
296301
}
302+
}else{
303+
// Only if we are destroying the tail t will be NULL
304+
assert(connection == mon_tail);
305+
mon_tail = t;
297306
}
298307

308+
/*
309+
head ... | t | connection | ... tail
310+
*/
299311
t = connection->monitoring.prev;
300312
if(t != NULL){
301313
assert(t->monitoring.next == connection);
302314
t->monitoring.next = connection->monitoring.next;
303315
if(t->monitoring.next == NULL) {
304-
assert(mon_head == connection);
305-
mon_head = t;
316+
assert(mon_tail == connection);
317+
mon_tail = t;
306318
}
319+
}else{
320+
// Only if we are destroying the head will t be null
321+
assert(mon_head == connection);
322+
mon_head = t;
307323
}
308324
}
325+
309326
static void reverse(char s[])
310327
{
311328
int i, j;
@@ -357,6 +374,7 @@ void monitoring_check(){
357374
mon_tail = mon_head = conn;
358375
conn->monitoring.next = conn->monitoring.prev = NULL;
359376
}
377+
conn->monitoring.next = NULL;
360378

361379
// If buffer wasnt cleared already, then we will need to disconnect
362380
if(conn->output_buffer != NULL){

0 commit comments

Comments
 (0)