Log a connection error before disconnecting

This makes the debug logs easier to read - previously we'd get an error
and disconnect. That causes unwinding of the state internally
(including lots of debug messages) and then eventually the actual error
that caused the disconnect.

Reshuffle this, so we see the "Connection error" first before all the
unwiding of the state, making it easier to spot what caused the actual
error.
This commit is contained in:
Peter Hutterer 2023-05-19 11:38:08 +10:00
parent 82e8f20fff
commit e21f14d69f
2 changed files with 3 additions and 5 deletions

View file

@ -726,6 +726,7 @@ connection_dispatch(struct source *source, void *userdata)
_unref_(brei_result) *result = brei_dispatch(ei->brei, source_get_fd(source),
lookup_object, ei);
if (result) {
log_warn(ei, "Connection error: %s", brei_result_get_explanation(result));
brei_drain_fd(source_get_fd(source));
ei_disconnect(ei);
}
@ -738,8 +739,6 @@ connection_dispatch(struct source *source, void *userdata)
"DISCONNECTED",
"DISCONNECTING",
};
if (result)
log_warn(ei, "Connection error: %s", brei_result_get_explanation(result));
if (old_state != ei->state)
log_debug(ei, "Connection dispatch: %s -> %s",

View file

@ -393,6 +393,8 @@ client_dispatch(struct source *source, void *userdata)
_unref_(brei_result) *result = brei_dispatch(client->brei, source_get_fd(source),
lookup_object, client);
if (result) {
log_warn(eis_client_get_context(client), "Client error: %s",
brei_result_get_explanation(result));
brei_drain_fd(source_get_fd(source));
eis_client_disconnect_with_reason(client,
brei_result_get_reason(result),
@ -406,9 +408,6 @@ client_dispatch(struct source *source, void *userdata)
"REQUESTED_DISCONNECT",
"DISCONNECTED",
};
if (result)
log_warn(eis_client_get_context(client), "Client error: %s",
brei_result_get_explanation(result));
if (old_state != client->state) {
assert(old_state < ARRAY_LENGTH(client_states));
assert(client->state < ARRAY_LENGTH(client_states));