Skip to content

Disposing of a CopilotSession after stopping the client results in exception #306

Description

@stephentoub

Opus wrote code that explicitly issued the StopAsync, which is how I noticed. Presumably the StopAsync isn't actually necessary, and that the client ideally shouldn't be stopped while there are active sessions, but disposal also should ideally be tolerant to such things.

Repro:

using GitHub.Copilot.SDK;

await using var client = new CopilotClient();
await using var session = await client.CreateSessionAsync();

await client.StopAsync();

results in this exception from the DisposeAsync from the await using cleanup:

Unhandled exception. System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'StreamJsonRpc.JsonRpc'.
   at Microsoft.Verify.NotDisposed(IDisposableObservable disposedValue, String message)
   at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult](RequestId id, String targetName, IReadOnlyList`1 arguments, IReadOnlyList`1 positionalArgumentDeclaredTypes, IReadOnlyDictionary`2 namedArgumentDeclaredTypes, CancellationToken cancellationToken, Boolean isParameterObject)
   at GitHub.Copilot.SDK.CopilotClient.InvokeRpcAsync[T](JsonRpc rpc, String method, Object[] args, CancellationToken cancellationToken)
   at GitHub.Copilot.SDK.CopilotSession.DisposeAsync()
   at Program.<Main>$(String[] args)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions