fix(backend): fixed panic in db service
This commit is contained in:
parent
3b8a2c19ef
commit
b646ba2a9e
3 changed files with 11 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
7
backend/pkg/db/cache/session.go
vendored
7
backend/pkg/db/cache/session.go
vendored
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue