{"record":{"id":"38e5ce05d83d5dd2","repo":"ginuerzh/gost","slug":"obfs4-context-not-inited","errorCode":null,"errorMessage":"obfs4 context not inited","messagePattern":"obfs4 context not inited","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"obfs.go","lineNumber":723,"sourceCode":"\t\tsf, err := t.ServerFactory(stateDir, &ptArgs)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tsargs := sf.Args()\n\n\t\tobfs4Map[node.Addr] = obfs4Context{sf: sf, sargs: sargs}\n\n\t\tlog.Log(\"[obfs4] server inited:\", obfs4ServerURL(node))\n\t}\n\n\treturn nil\n}\n\nfunc obfs4GetContext(addr string) (obfs4Context, error) {\n\tctx, ok := obfs4Map[addr]\n\tif !ok {\n\t\treturn obfs4Context{}, fmt.Errorf(\"obfs4 context not inited\")\n\t}\n\treturn ctx, nil\n}\n\nfunc obfs4ServerURL(node Node) string {\n\tctx, err := obfs4GetContext(node.Addr)\n\tif err != nil {\n\t\treturn \"\"\n\t}\n\n\tvalues := (*url.Values)(ctx.sargs)\n\tquery := values.Encode()\n\treturn fmt.Sprintf(\n\t\t\"%s+%s://%s/?%s\", //obfs4-cert=%s&iat-mode=%s\",\n\t\tnode.Protocol,\n\t\tnode.Transport,\n\t\tnode.Addr,\n\t\tquery,","sourceCodeStart":705,"sourceCodeEnd":741,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/obfs.go#L705-L741","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconn, err := obfs4ClientConn(conn, node) // init never ran\n// after\nif err := Obfs4Init(node, false); err != nil {\n    return nil, err\n}\nconn, err := obfs4ClientConn(conn, node)","handlingStrategy":"validation","validationCode":"// ensure init before use\nif err := Obfs4Init(node, isServer); err != nil {\n    return fmt.Errorf(\"obfs4 init for %s: %w\", node.Addr, err)\n}\n// then call obfs4ClientConn/obfs4ServerConn/obfs4ServerURL","typeGuard":null,"tryCatchPattern":"ctx, err := obfs4GetContext(addr)\nif err != nil {\n    if strings.Contains(err.Error(), \"not inited\") {\n        return fmt.Errorf(\"call Obfs4Init for %s first\", addr)\n    }\n    return err\n}","preventionTips":["Call Obfs4Init at startup for every obfs4 node","Use identical node.Addr strings at init and use","Never ignore Obfs4Init errors"],"tags":["obfs4","initialization","missing-state"],"backgroundTag":"not-initialized","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}