diff --git a/lib/context.c b/lib/context.c
index d1344595cfa0db1aea4092cb2142189ab6cf729e..f67476b1e3b602a0d622a9e4934fff8b68fbdd24 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 e4d33877ba55409c1401c2fb6674a8ab2cd43b86..74ce7c559cdfa36aa0f28deebe265d7cbd6a54e6 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()