ginuerzh/gost · error
obfs4 context not inited
Error message
obfs4 context not inited
What it means
obfs4GetContext looks up the pre-initialized obfs4Context for a node address. If Obfs4Init was never called (or failed) for that address, the lookup fails with this error, so the obfs server URL generation or client/server connection cannot proceed.
Source
Thrown at obfs.go:723
sf, err := t.ServerFactory(stateDir, &ptArgs)
if err != nil {
return err
}
sargs := sf.Args()
obfs4Map[node.Addr] = obfs4Context{sf: sf, sargs: sargs}
log.Log("[obfs4] server inited:", obfs4ServerURL(node))
}
return nil
}
func obfs4GetContext(addr string) (obfs4Context, error) {
ctx, ok := obfs4Map[addr]
if !ok {
return obfs4Context{}, fmt.Errorf("obfs4 context not inited")
}
return ctx, nil
}
func obfs4ServerURL(node Node) string {
ctx, err := obfs4GetContext(node.Addr)
if err != nil {
return ""
}
values := (*url.Values)(ctx.sargs)
query := values.Encode()
return fmt.Sprintf(
"%s+%s://%s/?%s", //obfs4-cert=%s&iat-mode=%s",
node.Protocol,
node.Transport,
node.Addr,
query,View on GitHub (pinned to a33fdbf4c9)
Solutions
- Ensure Obfs4Init is called for every obfs4 node address before any connection or URL generation.
- Verify the node.Addr used at init exactly matches the one used at dial/accept time (same host:port string).
- Check the return error of Obfs4Init at startup; do not continue if it failed.
- Enable debug logging to confirm the init sequence ran for the node in question.
Example fix
// before
conn, err := obfs4ClientConn(conn, node) // init never ran
// after
if err := Obfs4Init(node, false); err != nil {
return nil, err
}
conn, err := obfs4ClientConn(conn, node) Defensive patterns
Strategy: validation
Validate before calling
// ensure init before use
if err := Obfs4Init(node, isServer); err != nil {
return fmt.Errorf("obfs4 init for %s: %w", node.Addr, err)
}
// then call obfs4ClientConn/obfs4ServerConn/obfs4ServerURL Try / catch
ctx, err := obfs4GetContext(addr)
if err != nil {
if strings.Contains(err.Error(), "not inited") {
return fmt.Errorf("call Obfs4Init for %s first", addr)
}
return err
} Prevention
- Call Obfs4Init at startup for every obfs4 node
- Use identical node.Addr strings at init and use
- Never ignore Obfs4Init errors
When it happens
Trigger: Calling obfs4ServerURL, obfs4ClientConn, or obfs4ServerConn for an address absent from obfs4Map — Obfs4Init skipped, called with a different node.Addr, or the earlier init failed after the map check.
Common situations: Using an obfs node without the obfs=obfs4 init step; node address mismatch (hostname vs IP, port difference) between init and use; init error swallowed earlier so the map entry was never created.
Related errors
AI-assisted analysis of ginuerzh/gost@a33fdbf4c9 (2026-09-02).
Data as JSON: /api/errors/38e5ce05d83d5dd2.
Report an issue: GitHub.