{"record":{"id":"f85c6ce04074f4b2","repo":"lionsoul2014/ip2region","slug":"seek-to-d-w","errorCode":null,"errorMessage":"seek to %d: %w","messagePattern":"seek to (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"binding/golang/xdb/searcher.go","lineNumber":216,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"read region at %d: %w\", dataPtr, err)\n\t}\n\n\treturn string(regionBuff), nil\n}\n\n// do the data read operation based on the setting.\n// content buffer first or will read from the file.\n// this operation will invoke the Seek for file based read.\nfunc (s *Searcher) read(offset int64, buff []byte) error {\n\tif s.contentBuff != nil {\n\t\tcLen := copy(buff, s.contentBuff[offset:])\n\t\tif cLen != len(buff) {\n\t\t\treturn fmt.Errorf(\"incomplete read: readed bytes should be %d\", len(buff))\n\t\t}\n\t} else {\n\t\t_, err := s.dbReader.Seek(offset, 0)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"seek to %d: %w\", offset, err)\n\t\t}\n\n\t\ts.ioCount++\n\t\trLen, err := s.dbReader.Read(buff)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"handle read: %w\", err)\n\t\t}\n\n\t\tif rLen != len(buff) {\n\t\t\treturn fmt.Errorf(\"incomplete read: readed bytes should be %d\", len(buff))\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":198,"sourceCodeEnd":232,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/golang/xdb/searcher.go#L198-L232","documentation":"Go xdb searcher file-mode read: dbReader.Seek to the required offset failed before reading; the wrapped system error is typically an I/O fault or an offset beyond EOF, both signs of a truncated or damaged xdb.","triggerScenarios":"Negative or out-of-range offset passed to Seek (corrupted pointers from a corrupt xdb); the underlying file was closed; the file descriptor is invalid after the file was deleted/replaced on some filesystems.","commonSituations":"Keeping a searcher open after Close() was called; corrupted xdb header producing wild offsets; reading from a file on a flaky network mount.","solutions":["Ensure the searcher's file is still open (don't call Close on the file/xdb while searches are in flight).","Verify xdb integrity — corrupted index/header can produce invalid offsets.","Reopen the searcher/file and retry once on transient I/O errors.","Inspect err.Unwrap() for the syscall-level cause (EBADF, ESPIPE, etc.)."],"exampleFix":"// before\nfile.Close() // ... later\nregion, _ := searcher.Search(ctx, ip) // seek on closed file\n// after\nregion, err := searcher.Search(ctx, ip)\nif err != nil { return err }\n// close the file only when done searching\nfile.Close()","handlingStrategy":"try-catch","validationCode":"if f == nil { return errors.New(\"xdb file not open\") }\nif offset < 0 { return errors.New(\"negative read offset — corrupt xdb?\") }","typeGuard":null,"tryCatchPattern":"region, err := searcher.Search(ctx, ip)\nif err != nil {\n    var pErr *fs.PathError\n    if errors.As(errors.Unwrap(err), &pErr) || strings.Contains(err.Error(), \"seek to\") {\n        searcher, err = reopenSearcher() // file handle likely closed/stale\n    }\n    return err\n}","preventionTips":["Own the file lifecycle: close the searcher/file only at shutdown.","Recreate the searcher when the xdb file is replaced.","Avoid wrapping the raw *os.File in code that may close it early.","Treat 'seek to N' errors as corrupt-xdb or closed-handle signals."],"tags":["golang","io-error","seek","file-handle"],"backgroundTag":"seek-failed","analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}