Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
freemanzMrojo committed Jan 10, 2025
1 parent b2462eb commit abee6eb
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions muxdb/muxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,27 @@ func AddMetricsIfLocked(err error, event string) {
return
}

if pathErr, ok := err.(*os.PathError); ok {
isLockError := false

switch e := err.(type) {
case *os.PathError:
// Eventually calls to openFileNoLog https://go.dev/src/os/file_unix.go
if errno, ok := pathErr.Err.(syscall.Errno); ok && errno == syscall.EWOULDBLOCK {
metricLeveldbLock().AddWithLabel(1, map[string]string{"event": event})
if errno, ok := e.Err.(syscall.Errno); ok && errno == syscall.EWOULDBLOCK {
isLockError = true
}
} else if err == syscall.EWOULDBLOCK { // setFileLock https://github.com/vechain/goleveldb/blob/master/leveldb/storage/file_storage_unix.go#L50
metricLeveldbLock().AddWithLabel(1, map[string]string{"event": event})
} else if err == storage.ErrLocked { // If using sessions
case syscall.Errno:
// setFileLock https://github.com/vechain/goleveldb/blob/master/leveldb/storage/file_storage_unix.go#L50
if e == syscall.EWOULDBLOCK {
isLockError = true
}
case error:
// If using sessions
if e == storage.ErrLocked {
isLockError = true
}
}

if isLockError {
metricLeveldbLock().AddWithLabel(1, map[string]string{"event": event})
}
}
Expand Down

0 comments on commit abee6eb

Please sign in to comment.