Skip to content

[BUG] GET /channels/{channelId}/statistics intermittently returns 500 during undeploy of an unrelated channel #457

Open

Description

@mgaffigan

Repro:

  1. In one thread, loop: deploy channel B, send a message through it, remove channel B.
  2. In another thread, loop: GET /channels/{A}/statistics. GET /channels/statistics?channelId={A}&includeUndeployed=true fails the same way.

Expected:

  • A request naming channel A reads only what it needs to answer about channel A.

Actual:

  • Each request reads D_MS<n> for every channel the server knows about, A or not.
  • Roughly one request in forty fails with HTTP 500 under the loop above.
  • The server log shows
    DonkeyDaoException: java.sql.SQLSyntaxErrorException: Table/View 'D_MS<n>' does not exist,
    for the channel being removed, not for A.
  • The client sees only {"message":"Request failed.","status":"500"}, because serialising the
    SQLException into the error response throws as well.

Activity

  1. added
    bug
    on Sep 21, 2026
  2. tonygermano commented on Nov 26, 2026

    @tonygermano
    Member

    #516 fixes this for requests scoped to specific channels: they now read only those channels' statistics tables. Unscoped requests (e.g. GET /channels/statistics?includeUndeployed=true) still loop over every local channel in JdbcDao.getChannelStatistics and can still fail while a channel is being removed, so this issue should stay open after #516 merges.

    Notes for whoever picks up the rest. The obvious fix, catching the exception and skipping that channel, is not enough on its own:

    • PostgreSQL needs a rollback. Read connections run with auto-commit off, so on PostgreSQL one failed query aborts the transaction, and every later query in the loop fails ("current transaction is aborted") until it is rolled back. Skipping a channel means rolling back (or using a savepoint) and then continuing.
    • Detecting a dropped table isn't portable. There's no common SQL state for "table does not exist" across our five databases, and matching messages is fragile. A more reliable check is to re-query D_CHANNELS after a failure and skip the channel only if it's no longer there, rethrowing otherwise. The DAO's cached getLocalChannelIds() map can't be used for this, because it's loaded once per DAO and won't show a removal that happens mid-loop.
    • It needs testing on every database. Locking around DROP TABLE differs between Derby, PostgreSQL, MySQL, SQL Server and Oracle, so the race may show up as an error on some and as a wait on others. A fix should be checked on all five.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions