Skip to content

Fail loudly when a reply doesn't match its command - #18

Closed
henrikbjorn wants to merge 1 commit into
raw-api-responsefrom
reply-matches-command
Closed

henrikbjorn wants to merge 1 commit into
raw-api-responsefrom
reply-matches-command

Conversation

@henrikbjorn

Copy link
Copy Markdown
Member

Stacked on #17.

FreeSWITCH answers each command on a connection once, in order, and its replies carry no request id, so librevox hands each reply to the oldest waiting command. Nothing checked that the reply was the kind that command expects. If commands and replies ever fell out of step, a caller could silently get someone else's reply.

What changes:

  • Each waiting command records what it expects: an api/response for api, a command/reply for everything else.
  • A mismatch fails loudly: it raises Librevox::ProtocolError (a ConnectionError) for every waiting command, and the connection is closed.
  • A reply with no waiting command is dropped, as before.

Together with Job-UUID (bgapi), Application-UUID (app execution) and scoped variables (events an app causes), every response is either matched by id or checked against its command. None can be attributed to the wrong caller.

Test fakes: two replied with the wrong kind, which FreeSWITCH never does, so they now match real behaviour:

  • base_test: api test now gets an api/response.
  • outbound_apps_test: the sendmsg acknowledgement is fed before the unsolicited api/response.

Tests: bundle exec rake test gives 126 runs, including the new reply_matching_test.rb.

FreeSWITCH answers each command on a connection once, in order, and its
replies carry no request id, so librevox hands each reply to the oldest
waiting command. Nothing checked that the reply was the kind that command
expects. If commands and replies ever fell out of step, a caller could
silently get someone else's reply.

Each waiting command now records what it expects: an api/response for
`api`, a command/reply for everything else. A reply of the other kind
raises Librevox::ProtocolError (a ConnectionError) for every waiting
command, and the connection is closed. A reply with no waiting command
is dropped, as before.

Two test fakes replied with the wrong kind, which FreeSWITCH never does.
They now match real behaviour.
@henrikbjorn

Copy link
Copy Markdown
Member Author

Folded into #25, which collects these changes in one PR.

@henrikbjorn henrikbjorn closed this Oct 1, 2026
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.

1 participant