Skip to content

Audit event streaming worker cannot be called inside a transaction

Overview

After we rolled out Audit Event Streaming, @manojmj noticed a spike in caught exceptions in Sentry relating to the sidekiq worker. (https://sentry.gitlab.net/gitlab/gitlabcom/?query=is%3Aunresolved+AuditEventStreamingWorker.perform_async) Internal link

This is because some auditable actions (transferring projects, creating/updating feature flags) are done within a transactions and it is not possible to enqueue a sidekiq job from within a transaction.

Impact

  • Exception occurring with a relatively small proportion of Audit Events, and only where the ff_external_audit_events_namespace feature flag is enabled.
  • Exception is tracked within sentry.
  • Controller action is not halted, user-impact is minimal in the UI.
  • Audit event is saved, as expected.
  • Event expected to be streamed, is not streamed.

Suggested resolution

  • Use the AfterCommitQueue concern to perform the streaming after the transaction has finished.

Thanks @manojmj for the bug report and suggested resolution 💜

Edited by Dan Jensen