Skip to content
Browse files

Attempt to also get closing of connections to work.

  • Loading branch information...
1 parent fefe125 commit a5eb6aa3612b3e3fb999ac71917400c136b69c12 @skinkie skinkie committed Jan 5, 2014
Showing with 51 additions and 17 deletions.
  1. +8 −4 cherokee/admin_server.c
  2. +40 −9 cherokee/cherokee-tweak
  3. +0 −1 cherokee/handler_admin.c
  4. +3 −3 cherokee/server.c
View
12 cherokee/admin_server.c
@@ -214,18 +214,22 @@ cherokee_admin_server_reply_close_conn (cherokee_handler_t *hdl,
cherokee_server_t *server = HANDLER_SRV(hdl);
cherokee_buffer_t match = CHEROKEE_BUF_INIT;
- cherokee_buffer_fake_str (&match, "del server.connection ");
+ cherokee_buffer_fake_str (&match, "close server.connection ");
- if (cherokee_buffer_cmp_buf (question, &match)) {
+ if (strncasecmp (question->buf, match.buf, match.len)) {
return ret_error;
}
- begin = question->buf + 22;
+ begin = question->buf + match.len;
ret = cherokee_server_del_connection (server, begin);
cherokee_dwriter_dict_open (dwriter);
cherokee_dwriter_cstring (dwriter, "close");
- cherokee_dwriter_cstring (dwriter, ret == ret_ok ? "ok" : "failed");
+ if (ret == ret_ok) {
+ cherokee_dwriter_cstring (dwriter, "ok");
+ } else {
+ cherokee_dwriter_cstring (dwriter, "failed");
+ }
cherokee_dwriter_dict_close (dwriter);
return ret_ok;
View
49 cherokee/cherokee-tweak
@@ -44,16 +44,18 @@ USAGE = \
" cherokee-tweak [options] URL purge \n" \
" cherokee-tweak [options] URL sources \n" \
" cherokee-tweak [options] URL kill-source ID \n" \
+ " cherokee-tweak [options] URL close-connection ID \n" \
" cherokee-tweak [options] URL logrotate PATH \n" \
" cherokee-tweak [options] URL trace TRACE \n\n" \
" Commands:\n" \
" info Prints info about the server status\n" \
- " purge Purge objects from the cache\n\n" \
+ " purge Purge objects from the cache\n" \
" sources Prints a list of the info. sources\n" \
" kill-source Kill a remote information source\n" \
+ " close-connection Removes an active connection\n" \
" logrotate Rotates a local log file\n" \
" trace Manipulates the tracing mechanism\n" \
- " (to disable: trace off\n" \
+ " (to disable: trace off)\n\n" \
" Parameters:\n" \
" -h, --help Print this help\n" \
" -V, --version Print version and exit\n\n" \
@@ -63,18 +65,19 @@ USAGE = \
"Report bugs to http://bugs.cherokee-project.com\n"
-command = None
-url = None
-user = None
+command = None
+url = None
+user = None
password = None
-log = None
-trace = None
-ksource = None
+log = None
+trace = None
+ksource = None
+cconnection = None
def parse_args():
global command, url
global user, password
- global log, trace, ksource
+ global log, trace, ksource, cconnection
if '-h' in sys.argv or '--help' in sys.argv:
print USAGE
@@ -148,6 +151,10 @@ def parse_args():
ksource = sys.argv[argn]
argn += 1
return
+ elif command == 'close-connection':
+ cconnection = sys.argv[argn]
+ argn += 1
+ return
return usage()
@@ -248,6 +255,19 @@ def kill_source():
#
+# Close Connection
+#
+
+def close_connection():
+ # Query
+ responses_str = request (['close server.connection %s'%(cconnection)])
+ responses = eval_safe(responses_str)
+
+ # Report
+ print "Close connection %s: %s" %(cconnection, responses[0]['close'])
+ print
+
+#
# Info
#
@@ -291,12 +311,16 @@ def print_info():
# Connection details
print "Connections:"
for conn in conns:
+ print "\tID: %s" %(conn.get('id'))
print "\tRequest: %s" %(conn.get('request',''))
print "\tHandler: %s" %(conn.get('handler'))
print "\tPhase: %s" %(conn.get('phase'))
print "\tIncoming IP: %s" %(conn.get('ip'))
print "\tRX: %s" %(conn.get('rx'))
print "\tTX: %s" %(conn.get('tx'))
+ print "\tTotal size: %s" %(conn.get('total_size') or '')
+ print "\tPercentage: %s" %(conn.get('percent') or '')
+ print "\tIcon: %s" %(conn.get('icon'))
if conns.index(conn) < len(conns)-1:
print "\t---------------------"
print
@@ -394,6 +418,13 @@ def main():
kill_source()
else:
print "ERROR: Missing source ID parameter"
+
+ elif command == 'close-connection':
+ if cconnection:
+ close_connection()
+ else:
+ print "ERROR: Missing connection ID parameter"
+
elif command == 'trace':
if trace:
set_trace()
View
1 cherokee/handler_admin.c
@@ -123,7 +123,6 @@ process_request_line (cherokee_handler_admin_t *hdl, cherokee_buffer_t *line)
return cherokee_admin_server_reply_get_conns (HANDLER(hdl), &hdl->dwriter);
} else if (COMP (line->buf, "close server.connection")) {
return cherokee_admin_server_reply_close_conn (HANDLER(hdl), &hdl->dwriter, line);
-
}
SHOULDNT_HAPPEN;
View
6 cherokee/server.c
@@ -1946,7 +1946,7 @@ cherokee_server_del_connection (cherokee_server_t *srv, char *id_str)
list_for_each (t, &srv->thread_list) {
cherokee_thread_t *thread = THREAD(t);
- CHEROKEE_MUTEX_LOCK (&thread->ownership);
+// CHEROKEE_MUTEX_LOCK (&thread->ownership);
@skinkie
Cherokee Project member
skinkie added a note Jan 5, 2014

The problem here is that the code gets in a deadlock.

==21595== Thread #19: Attempt to re-lock a non-recursive lock I already hold
==21595==    at 0x402DCD1: pthread_mutex_lock (in /usr/lib64/valgrind/vgpreload_helgrind-amd64-linux.so)
==21595==    by 0x4C9CC7C: cherokee_server_del_connection (server.c:1949)
==21595==    by 0x7FAA639: cherokee_admin_server_reply_close_conn (admin_server.c:224)
==21595==    by 0x7FA9D5E: process_request_line (handler_admin.c:125)
==21595==    by 0x7FA9812: cherokee_handler_admin_read_post (handler_admin.c:252)
==21595==    by 0x4C9761A: cherokee_handler_read_post (handler.c:107)
==21595==    by 0x4C910B0: cherokee_connection_read_post (connection.c:686)
==21595==    by 0x4CA6339: process_active_connections (thread.c:1216)
==21595==    by 0x4CA71F1: cherokee_thread_step_MULTI_THREAD (thread.c:2067)
==21595==    by 0x4CA3BC1: thread_routine (thread.c:99)
==21595==    by 0x402D88D: ??? (in /usr/lib64/valgrind/vgpreload_helgrind-amd64-linux.so)
==21595==    by 0x4ECBF39: start_thread (in /lib64/libpthread-2.17.so)
==21595==  Lock was previously acquired
==21595==    at 0x402DE16: pthread_mutex_lock (in /usr/lib64/valgrind/vgpreload_helgrind-amd64-linux.so)
==21595==    by 0x4CA71D9: cherokee_thread_step_MULTI_THREAD (thread.c:2059)
==21595==    by 0x4CA3BC1: thread_routine (thread.c:99)
==21595==    by 0x402D88D: ??? (in /usr/lib64/valgrind/vgpreload_helgrind-amd64-linux.so)
==21595==    by 0x4ECBF39: start_thread (in /lib64/libpthread-2.17.so)

See potential solution in:
71bc6c8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
list_for_each (c, &THREAD(t)->active_list) {
cherokee_connection_t *conn = CONN(c);
@@ -1956,12 +1956,12 @@ cherokee_server_del_connection (cherokee_server_t *srv, char *id_str)
(conn->phase != phase_lingering))
{
conn->phase = phase_shutdown;
- CHEROKEE_MUTEX_UNLOCK (&thread->ownership);
+// CHEROKEE_MUTEX_UNLOCK (&thread->ownership);
return ret_ok;
}
}
}
- CHEROKEE_MUTEX_UNLOCK (&thread->ownership);
+// CHEROKEE_MUTEX_UNLOCK (&thread->ownership);
}
return ret_not_found;

0 comments on commit a5eb6aa

Please sign in to comment.
Something went wrong with that request. Please try again.