{"record":{"id":"38f13e7b3567d0f2","repo":"egametang/ET","slug":"service-discovery-response-error-request-reques","errorCode":null,"errorMessage":"service discovery response error, request: {requestName}, error: {error}, message: {message}","messagePattern":"service discovery response error, request: (.+?), error: (.+?), message: (.+?)","errorType":"exception","errorClass":"RpcException","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.servicediscovery/Scripts/Hotfix/Server/ServiceDiscoveryAgentSystem.cs","lineNumber":640,"sourceCode":"                        throw new Exception(\"service discovery agent disposed\");\n                    }\n\n                    if (rawResponse is not T response)\n                    {\n                        (rawResponse as MessageObject)?.Dispose();\n                        throw new Exception(\n                            $\"service discovery response type mismatch, request: {requestName}, actual: {rawResponse?.GetType().Name}\");\n                    }\n\n                    if (response.Error != ErrorCode.ERR_Success)\n                    {\n                        int error = response.Error;\n                        string message = response.Message;\n                        if (response is MessageObject messageObject)\n                        {\n                            messageObject.Dispose();\n                        }\n                        throw new RpcException(error,\n                            $\"service discovery response error, request: {requestName}, error: {error}, message: {message}\");\n                    }\n\n                    return response;\n                }\n                catch (Exception e)\n                {\n                    self = selfRef;\n                    if (self == null)\n                    {\n                        throw;\n                    }\n\n                    bool shouldResolveMaster = self.ShouldResolveMasterAfterFailure(e);\n                    if (shouldResolveMaster)\n                    {\n                        self.InvalidateEndpointAndTriggerBackgroundRegister(\"call-failure\");\n                    }","sourceCodeStart":622,"sourceCodeEnd":658,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.servicediscovery/Scripts/Hotfix/Server/ServiceDiscoveryAgentSystem.cs#L622-L658","documentation":"RpcException thrown at line 640 in ForwardToDiscoveryByFailoverCore: the master returned a response with response.Error != ERR_Success. The error code and message from the response are wrapped into an RpcException and propagated. The actual error code comes from the master's handler (e.g. ERR_ServiceDiscoveryInvalidArgument, ERR_ServiceDiscoveryPersistenceFailed, ERR_ServiceDiscoveryFollowerRejected).","triggerScenarios":"The forwarded request reached the master but the master rejected it: invalid arguments, persistence (DB) failure, follower rejection (the node is not the master), or operation failure. ShouldResolveMasterAfterFailure decides whether to failover based on the code.","commonSituations":"The agent contacted a stale master that is now a follower (ERR_ServiceDiscoveryFollowerRejected); the DB write behind the master failed (ERR_ServiceDiscoveryPersistenceFailed); the request payload failed validation (ERR_ServiceDiscoveryInvalidArgument); the target master scene errored internally.","solutions":["Inspect the wrapped error code in the RpcException to identify the root cause (follower rejection -> re-resolve master; persistence -> check DB; invalid argument -> fix payload).","For follower-rejection/master-unavailable, allow the failover loop to re-resolve and retry.","For persistence errors, verify DB connectivity and capacity.","For invalid-argument errors, validate the request before forwarding."],"exampleFix":"// before\nvar resp = await agent.ForwardToDiscoveryByFailover<T>(req, name);\n\n// after\ncatch (RpcException e) when (e.Error == ErrorCode.ERR_ServiceDiscoveryFollowerRejected)\n{\n    // master moved; the loop already invalidates and retries; surface to caller if exhausted\n}\ncatch (RpcException e) when (e.Error == ErrorCode.ERR_ServiceDiscoveryPersistenceFailed)\n{\n    // check DB health\n}","handlingStrategy":"try-catch","validationCode":"// Validate request payload before forwarding to avoid invalid-argument errors.\nif (!ServiceDiscoveryHelper.TryValidateRequiredActorId(req.AgentActorId, nameof(req), nameof(req.AgentActorId), out _))\n{\n    return; // fix payload instead of forwarding\n}","typeGuard":null,"tryCatchPattern":"catch (RpcException e)\n{\n    switch (e.Error)\n    {\n        case ErrorCode.ERR_ServiceDiscoveryFollowerRejected:\n        case ErrorCode.ERR_ServiceDiscoveryMasterUnavailable:\n            // let failover re-resolve; retry at higher level if exhausted\n            break;\n        case ErrorCode.ERR_ServiceDiscoveryPersistenceFailed:\n            Log.Error($\"discovery DB failure: {e.Message}\");\n            break;\n        default:\n            Log.Error($\"discovery response error {e.Error}: {e.Message}\");\n            break;\n    }\n}","preventionTips":["Map each known error code to a remediation (DB health, master re-election, payload fix).","Validate payloads before forwarding.","Keep the DB healthy to avoid persistence errors."],"tags":["csharp","et-framework","service-discovery","rpc","master-election","database","validation"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}