Skip to content

Client transport error handling - #70

Merged
garethpotter merged 5 commits into
mainfrom
client-transport-error-handling
Aug 5, 2026
Merged

Client transport error handling#70
garethpotter merged 5 commits into
mainfrom
client-transport-error-handling

Conversation

@amitchone

@amitchone amitchone commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

This came about because of an edge case testing on BP hardware where the isolated comms were killed whilst a request/response context was still open - managed to recreate somewhat reliably creating a client transport allocated on the stack.

Ultimately, the exec (in this case) call timed out and then the transport goes out of scope, but the driver callback still points to that memory, causing all sorts of issues.

The static orphanage just gives us a place to redirect the callback to with a bunch noops and then die safely.

Claude then reviewed it and saw a couple of other issues that were also fixed as a part of this PR

@amitchone
amitchone requested a review from garethpotter August 4, 2026 16:15
@garethpotter

Copy link
Copy Markdown
Collaborator

Can you provide a little bit of context on what some of this is for? I think I get it but it would be useful to have an overview in English.

Comment thread src/ThingSetClient.cpp Outdated
Comment on lines 51 to 57
if (received < 2 || _rxBuffer[1] != 0xF6) {
return ThingSetResult(ThingSetStatusCode::internalServerError);
}

// return size having accounted for response code and null
responseSize -= 2;
responseSize = (size_t)received - 2;
*responseBuffer = &_rxBuffer[2];

@garethpotter garethpotter Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel the first and second of these 2s could perhaps be a const somewhere (and possibly even the third).


// name needs to be this to make stupid twister check pass
#define ZCLIENT_SERVER_TEST(test_name, Body) \
// variadic so test bodies may contain top-level commas (e.g. template args)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Glorious.

Comment on lines +990 to +996
if (ctx->filter_id < 0) {
/* Without this check a full filter table used to be reported as a
* successful bind, and every subsequent exchange timed out */
LOG_ERR("Failed to add RX filter for %x:%x (err %d)", filter.id, filter.mask,
ctx->filter_id);
return ISOTP_NO_FREE_FILTER;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My main comment with this would be that as it stands, it's now quite hairy: it's very important that one does not forget to increment or decrement the pending_cb count in an early return. I wonder if at the very least a local function might reduce some of the instances where this needs to be done, i.e.:

static int isotp_can_send(const struct device *can_dev, const can_frame *frame, ..., atomic_t *pending_cb)
{
    atomic_inc(pending_cb);
    int ret = can_send(...);
    if (ret) {
        atomic_dec(pending_cb);
    }
    return ret;
}

@garethpotter garethpotter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As commented elsewhere, it would be useful to have an overview of what this is trying to do, but I think I get it and there's nothing too controversial from what I can see.

@amitchone

Copy link
Copy Markdown
Collaborator Author

Can you provide a little bit of context on what some of this is for? I think I get it but it would be useful to have an overview in English.

As commented elsewhere, it would be useful to have an overview of what this is trying to do, but I think I get it and there's nothing too controversial from what I can see.

Updated description

@garethpotter
garethpotter merged commit e04f2f6 into main Aug 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants