Skip to content

Commit

Permalink
Fix bridge pollfd corruption on Windows.
Browse files Browse the repository at this point in the history
Closes #2173. Thanks to Niclas Lindgren.
  • Loading branch information
ralight committed Jun 8, 2021
1 parent 104b94d commit 238b686
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -9,6 +9,8 @@ Broker:
Closes #2207.
- Improve QoS 0 outgoing packet queueing.
- Fix non-reachable bridge blocking the broker on Windows. Closes #2172.
- Fix possible corruption of pollfd array on Windows when bridges were
reconnecting. Closes #2173.

Clients:
- If sending mosquitto_sub output to a pipe, mosquitto_sub will now detect
Expand Down
8 changes: 8 additions & 0 deletions src/bridge.c
Expand Up @@ -245,6 +245,7 @@ int bridge__connect_step1(struct mosquitto *context)
rc = net__try_connect_step1(context, context->bridge->addresses[context->bridge->cur_address].address);
if(rc > 0 ){
if(rc == MOSQ_ERR_TLS){
mux__delete(context);
net__socket_close(context);
return rc; /* Error already printed */
}else if(rc == MOSQ_ERR_ERRNO){
Expand All @@ -270,6 +271,7 @@ int bridge__connect_step2(struct mosquitto *context)
rc = net__try_connect_step2(context, context->bridge->addresses[context->bridge->cur_address].port, &context->sock);
if(rc > 0){
if(rc == MOSQ_ERR_TLS){
mux__delete(context);
net__socket_close(context);
return rc; /* Error already printed */
}else if(rc == MOSQ_ERR_ERRNO){
Expand Down Expand Up @@ -298,6 +300,7 @@ int bridge__connect_step3(struct mosquitto *context)
rc = net__socket_connect_step3(context, context->bridge->addresses[context->bridge->cur_address].address);
if(rc > 0){
if(rc == MOSQ_ERR_TLS){
mux__delete(context);
net__socket_close(context);
return rc; /* Error already printed */
}else if(rc == MOSQ_ERR_ERRNO){
Expand Down Expand Up @@ -326,6 +329,7 @@ int bridge__connect_step3(struct mosquitto *context)
}else if(rc == MOSQ_ERR_EAI){
log__printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", gai_strerror(errno));
}
mux__delete(context);
net__socket_close(context);
return rc;
}
Expand Down Expand Up @@ -437,6 +441,7 @@ int bridge__connect(struct mosquitto *context)

if(rc > 0){
if(rc == MOSQ_ERR_TLS){
mux__delete(context);
net__socket_close(context);
return rc; /* Error already printed */
}else if(rc == MOSQ_ERR_ERRNO){
Expand Down Expand Up @@ -466,6 +471,7 @@ int bridge__connect(struct mosquitto *context)
}else if(rc2 == MOSQ_ERR_EAI){
log__printf(NULL, MOSQ_LOG_ERR, "Error creating bridge: %s.", gai_strerror(errno));
}
mux__delete(context);
net__socket_close(context);
return rc2;
}
Expand Down Expand Up @@ -751,6 +757,7 @@ void bridge_check(void)
COMPAT_CLOSE(context->bridge->primary_retry_sock);
context->bridge->primary_retry_sock = INVALID_SOCKET;
context->bridge->primary_retry = 0;
mux__delete(context);
net__socket_close(context);
context->bridge->cur_address = 0;
}
Expand All @@ -761,6 +768,7 @@ void bridge_check(void)
COMPAT_CLOSE(context->bridge->primary_retry_sock);
context->bridge->primary_retry_sock = INVALID_SOCKET;
context->bridge->primary_retry = 0;
mux__delete(context);
net__socket_close(context);
context->bridge->cur_address = context->bridge->address_count-1;
}else{
Expand Down

2 comments on commit 238b686

@NiclasLindgren
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the same as I saw, as long as no mux__delete wasn't missed before a net__socket_close, I did the same inside net__socket_close, which felt wrong(that layer shouldn't know about mux really), but was quick test.

@ralight
Copy link
Contributor Author

@ralight ralight commented on 238b686 Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'm not entirely happy with how this is now but it's certainly better than being in net__socket_close().

Please sign in to comment.