diff --git a/src/sbbs3/services.c b/src/sbbs3/services.c
index 9876e6a03ffe5c32f159e07f086a9177bc34cec2..2cb04ee1e719876eb6c2038ffd01900b21cdd8da 100644
--- a/src/sbbs3/services.c
+++ b/src/sbbs3/services.c
@@ -712,8 +712,6 @@ static void js_service_thread(void* arg)
 //		lprintf("%04d %s JS_DestroyScript",socket,service->protocol);
 		JS_DestroyScript(js_cx, js_script);
 	}
-	close_socket(socket);
-
 //	lprintf("%04d %s JS_DestroyContext",socket,service->protocol);
 	JS_DestroyContext(js_cx);	/* Free Context */
 
@@ -741,6 +739,7 @@ static void js_service_thread(void* arg)
 	active_clients--;
 	update_clients();
 	client_off(socket);
+	close_socket(socket);
 
 	thread_down();
 }