{"record":{"id":"400eb0168cb1e9a8","repo":"hibiken/asynq","slug":"redis-connection-is-shared-so-the-client-can-t-be","errorCode":null,"errorMessage":"redis connection is shared so the Client can't be closed through asynq","messagePattern":"redis connection is shared so the Client can't be closed through asynq","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client.go","lineNumber":352,"sourceCode":"\nconst (\n\t// Default max retry count used if nothing is specified.\n\tdefaultMaxRetry = 25\n\n\t// Default timeout used if both timeout and deadline are not specified.\n\tdefaultTimeout = 30 * time.Minute\n)\n\n// Value zero indicates no timeout and no deadline.\nvar (\n\tnoTimeout  time.Duration = 0\n\tnoDeadline time.Time     = time.Unix(0, 0)\n)\n\n// Close closes the connection with redis.\nfunc (c *Client) Close() error {\n\tif c.sharedConnection {\n\t\treturn fmt.Errorf(\"redis connection is shared so the Client can't be closed through asynq\")\n\t}\n\treturn c.broker.Close()\n}\n\n// Enqueue enqueues the given task to a queue.\n//\n// Enqueue returns TaskInfo and nil error if the task is enqueued successfully, otherwise returns a non-nil error.\n//\n// The argument opts specifies the behavior of task processing.\n// If there are conflicting Option values the last one overrides others.\n// Any options provided to NewTask can be overridden by options passed to Enqueue.\n// By default, max retry is set to 25 and timeout is set to 30 minutes.\n//\n// If no ProcessAt or ProcessIn options are provided, the task will be pending immediately.\n//\n// Enqueue uses context.Background internally; to specify the context, use EnqueueContext.\nfunc (c *Client) Enqueue(task *Task, opts ...Option) (*TaskInfo, error) {\n\treturn c.EnqueueContext(context.Background(), task, opts...)","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/hibiken/asynq/blob/d135f1439bee74e989b7f9b41ecd542cc87f024a/client.go#L334-L370","documentation":"Guard in Client.Close: the client was created with a Redis connection owned elsewhere (e.g. a user-supplied redis.UniversalClient via RedisClientFromClient, or shared with a Server), so asynq will not close it. Closing would break other users of the shared connection; the caller who owns the connection must close it themselves.","triggerScenarios":"Thrown at client.go:352 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Close the redis connection yourself via the shared redis client instead of calling Client.Close()","Create the Client with NewClient (own connection) rather than NewClientFromRedisClient if you want asynq to manage closing"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d135f1439bee74e989b7f9b41ecd542cc87f024a","analyzedAt":"2026-09-07T19:02:34.660Z","contentChangedAt":"2026-09-07T19:02:34.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}