mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2026-12-05 06:34:30 +09:00
Pull request: AGDNS-3850-fix-two-instances
Squashed commit of the following:
commit 8c87d6eed9908365ffbd73ec5e5c7c548e5b9019
Merge: 6537f6a9d 9f7f8663f
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Apr 8 10:56:51 2026 +0700
Merge remote-tracking branch 'origin/master' into AGDNS-3850-fix-two-instances
commit 6537f6a9dbff67343316e77416e417e19ba37ac1
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Wed Apr 8 10:17:31 2026 +0700
aghuser: add logger for bbolt
commit 2e879788bdf73d84adb09ee6df1e1786f0435013
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date: Tue Apr 7 13:33:33 2026 +0700
aghuser: add sessions db timeout
This commit is contained in:
1 parent
9f7f8663ff
commit
4dc7d9d39a
1 file changed
+23
-2
@@ -87,6 +87,11 @@ type DefaultSessionStorage struct {
|
||||
sessionTTL time.Duration
|
||||
}
|
||||
|
||||
// dbOpenTimeout is the maximum duration to wait for opening the bbolt database.
|
||||
//
|
||||
// TODO(a.garipov): Consider making configurable.
|
||||
const dbOpenTimeout = 1 * time.Second
|
||||
|
||||
// NewDefaultSessionStorage returns the new properly initialized
|
||||
// *DefaultSessionStorage.
|
||||
func NewDefaultSessionStorage(
|
||||
@@ -103,8 +108,10 @@ func NewDefaultSessionStorage(
|
||||
}
|
||||
|
||||
dbFilename := conf.DBPath
|
||||
// TODO(s.chzhen): Pass logger with options.
|
||||
ds.db, err = bbolt.Open(dbFilename, aghos.DefaultPermFile, nil)
|
||||
ds.db, err = bbolt.Open(dbFilename, aghos.DefaultPermFile, &bbolt.Options{
|
||||
Timeout: dbOpenTimeout,
|
||||
Logger: newBBoltLogger(ctx, ds.logger),
|
||||
})
|
||||
if err != nil {
|
||||
ds.logger.ErrorContext(ctx, "opening db %q: %w", dbFilename, err)
|
||||
if errors.Is(err, berrors.ErrInvalid) {
|
||||
@@ -124,6 +131,20 @@ func NewDefaultSessionStorage(
|
||||
return ds, nil
|
||||
}
|
||||
|
||||
// newBBoltLogger returns a new [*bbolt.DefaultLogger] that logs messages using
|
||||
// the given [slog.Logger]. l must not be nil.
|
||||
func newBBoltLogger(ctx context.Context, l *slog.Logger) (bl *bbolt.DefaultLogger) {
|
||||
bl = &bbolt.DefaultLogger{
|
||||
Logger: slog.NewLogLogger(l.Handler(), slog.LevelDebug),
|
||||
}
|
||||
|
||||
if l.Enabled(ctx, slog.LevelDebug) {
|
||||
bl.EnableDebug()
|
||||
}
|
||||
|
||||
return bl
|
||||
}
|
||||
|
||||
// loadSessions loads web user sessions from the bbolt database.
|
||||
func (ds *DefaultSessionStorage) loadSessions(ctx context.Context) (err error) {
|
||||
tx, err := ds.db.Begin(true)
|
||||
|
||||
Reference in new issue
Block a user