diff --git a/backend/cmd/db/main.go b/backend/cmd/db/main.go index 321e73829..7928b4bb8 100644 --- a/backend/cmd/db/main.go +++ b/backend/cmd/db/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "log" "openreplay/backend/internal/config/db" "openreplay/backend/internal/db/datasaver" @@ -65,7 +66,7 @@ func main() { session, err := pg.GetSession(sessionID) if session == nil { - if err != nil { + if err != nil && !errors.Is(err, cache.NilSessionInCacheError) { log.Printf("Error on session retrieving from cache: %v, SessionID: %v, Message: %v", err, sessionID, msg) } return diff --git a/backend/pkg/db/cache/session.go b/backend/pkg/db/cache/session.go index 64945e06f..4ba56ff2a 100644 --- a/backend/pkg/db/cache/session.go +++ b/backend/pkg/db/cache/session.go @@ -1,14 +1,19 @@ package cache import ( + "errors" "github.com/jackc/pgx/v4" . "openreplay/backend/pkg/db/types" ) +var NilSessionInCacheError = errors.New("nil session in error") + func (c *PGCache) GetSession(sessionID uint64) (*Session, error) { if s, inCache := c.sessions[sessionID]; inCache { - // TODO: review. Might cause bugs in case of multiple PG instances + if s == nil { + return s, NilSessionInCacheError + } return s, nil } s, err := c.Conn.GetSession(sessionID) diff --git a/backend/pkg/sessions/builder.go b/backend/pkg/sessions/builder.go index d55c9e1bc..e764a7f20 100644 --- a/backend/pkg/sessions/builder.go +++ b/backend/pkg/sessions/builder.go @@ -53,11 +53,11 @@ func (b *builder) handleMessage(message Message, messageID uint64) { return } if timestamp < b.timestamp { - log.Printf("skip message with wrong timestamp, sessID: %d, msgID: %d, type: %d", b.sessionID, messageID, message.TypeID()) - return + log.Printf("skip message with wrong timestamp, sessID: %d, msgID: %d, type: %d, msgTS: %d, lastTS: %d", b.sessionID, messageID, message.TypeID(), timestamp, b.timestamp) + } else { + b.timestamp = timestamp } - b.timestamp = timestamp b.lastSystemTime = time.Now() for _, p := range b.processors { if rm := p.Handle(message, messageID, b.timestamp); rm != nil {