Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1641223

Summary: Can't create a new session in foreman: integer out of range
Product: Red Hat Satellite Reporter: Alexey Masolov <amasolov>
Component: Users & RolesAssignee: Suraj Patil <supatil>
Status: CLOSED ERRATA QA Contact: Radovan Drazny <rdrazny>
Severity: high Docs Contact:
Priority: high    
Version: 6.4CC: akapse, amasolov, andrew.schofield, baitken, bbuckingham, cmarinea, dhlavacd, inecas, jko, mhulan, oezr, oprazak, pdudley, satellite6-bugs, sthirugn, wpinheir
Target Milestone: 6.7.0Keywords: FieldEngineering, PrioBumpField, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: foreman-1.24.1.5-1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-04-14 13:23:25 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Alexey Masolov 2018-10-20 03:56:02 UTC
Description of problem:
Can't open a new foreman session. WebUI gives "We're sorry, but something went wrong.". API calls return Error 500. 

=== production.log ===
2018-10-19 11:46:36 39364d1c [app] [F]
 | ActiveRecord::StatementInvalid (PG::Error: ERROR:  integer out of range
 | : INSERT INTO "sessions" ("created_at", "data", "session_id", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"):
 |   lib/middleware/tagged_logging.rb:18:in `call'
===

=== postgresql.log ===
2018-10-20 14:40:18 AEDT STATEMENT:  INSERT INTO "sessions" ("session_id", "data", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"
2018-10-20 14:40:18 AEDT ERROR:  integer out of range
2018-10-20 14:40:18 AEDT STATEMENT:  INSERT INTO "sessions" ("session_id", "data", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"
===

Version-Release number of selected component (if applicable):
Satellite 6.2, 6.3, 6.4

How reproducible:
100%

Steps to Reproduce:
1. Clean your sessions to avoid further mess by running 'foreman-rake db:sessions:clear'
2. Modify your last value in foreman.sessions_id_seq to something bigger than integer. So the next value for ID in foreman.sessions will be bigger than integer. Like:

foreman=# alter sequence sessions_id_seq restart with 2151782968;
ALTER SEQUENCE
foreman=# select * from sessions_id_seq;
  sequence_name  | last_value | start_value | increment_by |      max_value      | min_value | cache_value | log_cnt | is_cycled | is_called
-----------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
 sessions_id_seq | 2151782969 |           1 |            1 | 9223372036854775807 |         1 |           1 |      31 | f         | t
(1 row)
foreman=# \d+ sessions;
                                                         Table "public.sessions"
   Column   |            Type             |                       Modifiers                       | Storage  | Stats target | Description
------------+-----------------------------+-------------------------------------------------------+----------+--------------+-------------
 id         | integer                     | not null default nextval('sessions_id_seq'::regclass) | plain    |              |
 session_id | character varying(255)      | not null                                              | extended |              |
 data       | text                        |                                                       | extended |              |
 created_at | timestamp without time zone |                                                       | plain    |              |
 updated_at | timestamp without time zone |                                                       | plain    |              |
Indexes:
    "sessions_pkey" PRIMARY KEY, btree (id)
    "index_sessions_on_session_id" btree (session_id)
    "index_sessions_on_updated_at" btree (updated_at)

3. Done. 


Actual results:
"We're sorry, but something went wrong." in the webui. Not able to register new servers, etc. 

Expected results:
Functionality as usual.

Additional info:
Restart the sequence with 1 to bring your Satellite back online. 

foreman=# alter sequence sessions_id_seq restart with 1;
ALTER SEQUENCE

Comment 5 Ondřej Pražák 2019-02-07 07:22:38 UTC
Created redmine issue http://projects.theforeman.org/issues/26009 from this bug

Comment 9 Kavita 2019-10-07 11:05:33 UTC
*** Bug 1758292 has been marked as a duplicate of this bug. ***

Comment 15 Ondřej Ezr 2020-02-18 15:01:47 UTC
Linking an issue, that contains an easyfix.

Comment 19 Radovan Drazny 2020-03-10 09:50:31 UTC
Verified on Sat 6.7 Snap 15.

Logged out from the WebUI, run 'foreman-rake db:sessions:clear'

$ sudo -u foreman psql

foreman=> select * from sessions_id_seq;
  sequence_name  | last_value | start_value | increment_by |      max_value      | min_value | cache_value | log_cnt | is_cycled | is_called 
-----------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
 sessions_id_seq |        269 |           1 |            1 | 9223372036854775807 |         1 |           1 |      29 | t         | t
(1 row)

The max value has been set to the PG bigint value.

foreman=> alter sequence sessions_id_seq restart with 9223372036854775807;                                          
ALTER SEQUENCE

foreman=> select * from sessions_id_seq;
  sequence_name  |     last_value      | start_value | increment_by |      max_value      | min_value | cache_value | log_cnt | is_cycled | is_called 
-----------------+---------------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
 sessions_id_seq | 9223372036854775807 |           1 |            1 | 9223372036854775807 |         1 |           1 |       0 | t         | f
(1 row)


Logged back into the WebUI, did some clicking around.


foreman=> select * from sessions_id_seq;
  sequence_name  | last_value | start_value | increment_by |      max_value      | min_value | cache_value | log_cnt | is_cycled | is_called 
-----------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
 sessions_id_seq |          5 |           1 |            1 | 9223372036854775807 |         1 |           1 |      29 | t         | t
(1 row)


The value correctly rolled over the bigint limit, and started the sequence from 1 again.

Comment 22 errata-xmlrpc 2020-04-14 13:23:25 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:1454