diff --git a/lib/context.c b/lib/context.c index d1344595..f67476b1 100644 --- a/lib/context.c +++ b/lib/context.c @@ -197,6 +197,11 @@ lws_protocol_init(struct lws_context *context) struct lws wsi; int n; + if (context->doing_protocol_init) + return 0; + + context->doing_protocol_init = 1; + memset(&wsi, 0, sizeof(wsi)); wsi.context = context; @@ -261,8 +266,12 @@ lws_protocol_init(struct lws_context *context) */ if (vh->protocols[n].callback(&wsi, LWS_CALLBACK_PROTOCOL_INIT, NULL, - (void *)pvo, 0)) + (void *)pvo, 0)) { + lwsl_err("%s: vhost %s failed init\n", __func__, + vh->protocols[n].name); + context->doing_protocol_init = 0; return 1; + } } vh->created_vhost_protocols = 1; @@ -270,6 +279,8 @@ next: vh = vh->vhost_next; } + context->doing_protocol_init = 0; + if (!context->protocol_init_done) lws_finalize_startup(context); diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index e4d33877..74ce7c55 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -1116,6 +1116,7 @@ struct lws_context { unsigned int requested_kill:1; unsigned int protocol_init_done:1; unsigned int ssl_gate_accepts:1; + unsigned int doing_protocol_init; /* * set to the Thread ID that's doing the service loop just before entry * to poll indicates service thread likely idling in poll()