ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "job_canceled"

https://sentry.gitlab.net/gitlab/gitlabcom/issues/2437130/?referrer=gitlab_plugin

PG::InvalidTextRepresentation: ERROR:  invalid input syntax for integer: "job_canceled"
LINE 1: ... AND "ci_build_pending_states"."failure_reason" = 'job_cance...
                                                             ^

  active_record/connection_adapters/postgresql_adapter.rb:675:in `exec_params'
    @connection.exec_params(sql, type_casted_binds)
  active_record/connection_adapters/postgresql_adapter.rb:675:in `block (2 levels) in exec_no_cache'
    @connection.exec_params(sql, type_casted_binds)
  active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
    yield
  active_support/concurrency/share_lock.rb:187:in `yield_shares'
    yield
  active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
    @lock.yield_shares(compatible: [:load]) do
...
(218 additional frame(s) were not displayed)

ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR:  invalid input syntax for integer: "job_canceled"
LINE 1: ... AND "ci_build_pending_states"."failure_reason" = 'job_cance...
                                                             ^

Root cause

This problem happens because a Runner-internal failure reason is being sent to the Rails app, assuming that it will ignore unknown values. The logic change was introduced in gitlab-runner!2382 (merged).

Mitigation

  1. Have Rails app publish which failure_reasons it understands, in Build#features;
  2. Have Runner consume failure_reasons and return unknown_failure if the failure reason is not part of the failure_reasons array;
Edited by Pedro Pombeiro