go-macaron / session

Package session is a middleware that provides the session management of Macaron.
Apache License 2.0
26 stars 27 forks source link

Fix replication error with mysql based session on gc #17

Closed 0x20h closed 7 years ago

0x20h commented 7 years ago

Hi there,

we're using grafana with mysql backend and a master-master setup and we get replication errors from time to time. There is an error case when side B had a new session record after the GC was triggered on side A, leading to expiry > UNIX_TIMESTAMP(NOW()) when the statement is executed on side B (since NOW() was replaced with the actual timestamp on side A, see http://dev.mysql.com/doc/refman/5.7/en/replication-features-functions.html). As expiry is unsigned, this results in a failed query and broken replication.

The error we got:

Last_SQL_Error: Error 'BIGINT UNSIGNED value is out of range in '(unix_timestamp(now()) - `grafana`.`session`.`expiry`)'' on query. Default database: 'grafana'. 
Query: 'DELETE FROM session WHERE UNIX_TIMESTAMP(NOW()) - expiry > 86400'

This change fixes the out of range error.

0x20h commented 7 years ago

@Unknwon I also removed the 1.3 tests

unknwon commented 7 years ago

Thanks!