diff options
| author | Felix Fietkau | 2025-05-16 10:27:07 +0000 |
|---|---|---|
| committer | Felix Fietkau | 2025-05-16 10:27:50 +0000 |
| commit | 88e6325092bf1d1cfa877cd220670fa7cc2fad03 (patch) | |
| tree | e10920d4def70ba044743be0967bc60c55e1dca4 | |
| parent | afa57cce0aff82f4a7a0e509d4387ebc23dd3be7 (diff) | |
| download | ubus-88e6325092bf1d1cfa877cd220670fa7cc2fad03.tar.gz | |
libubus: flush all pending requests on connection loss
This avoids running into timeouts when channel connections are lost.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
| -rw-r--r-- | libubus-io.c | 4 | ||||
| -rw-r--r-- | libubus-req.c | 10 | ||||
| -rw-r--r-- | libubus.h | 1 |
3 files changed, 14 insertions, 1 deletions
diff --git a/libubus-io.c b/libubus-io.c index 16c1c14..beea3bf 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -328,8 +328,10 @@ void __hidden ubus_handle_data(struct uloop_fd *u, unsigned int events) if (!ctx->stack_depth) ctx->pending_timer.cb(&ctx->pending_timer); - if (u->eof) + if (u->eof) { + ubus_flush_requests(ctx); ctx->connection_lost(ctx); + } } void __hidden ubus_poll_data(struct ubus_context *ctx, int timeout) diff --git a/libubus-req.c b/libubus-req.c index 3e8d55c..4b718dc 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -137,6 +137,16 @@ static int64_t get_time_msec(void) return val; } +void ubus_flush_requests(struct ubus_context *ctx) +{ + struct ubus_request *req; + + while (!list_empty(&ctx->requests)) { + req = list_first_entry(&ctx->requests, struct ubus_request, list); + ubus_set_req_status(req, UBUS_STATUS_TIMEOUT); + } +} + int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req, int req_timeout) { @@ -264,6 +264,7 @@ int ubus_channel_connect(struct ubus_context *ctx, int fd, ubus_handler_t handler); int ubus_channel_create(struct ubus_context *ctx, int *remote_fd, ubus_handler_t handler); +void ubus_flush_requests(struct ubus_context *ctx); static inline bool ubus_context_is_channel(struct ubus_context *ctx) |