I ran into a problem while waiting for the user to approve the application during the OAuth2 process. It was inconsistent and started happening only after I updated the Jira version (Data Center from 9.12 to 11.3).
While the HttpListener is supposed to be waiting for the user to response, on this line:
var httpListenerContext = await httpListener.GetContextAsync().ConfigureAwait(false);
This exception was thrown immediately, before the user has a chance to do anything.
System.Net.HttpListenerException (995): The I/O operation has been aborted because of either a thread exit or an application request.
I am using the LocalhostCodeReceiver class.
I thought it was a problem with Jira, due to the upgrade, but I tracked the problem down to this line in UriHttpListenerExtensions:
var listenTask = Task.Factory.StartNew(..., cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default).ConfigureAwait(false);
If I replaced LongRunning with None (the default), or Task.Run, then the problem went away.
I've found some documentation that Task.Factory.StartNew should not be used with TaskCreationOptions.LongRunning in many cases.
I'm not sure why it wasn't a problem with the previous version of Jira and only started happening now.
I was able to workaround this problem in my own application, but I'm adding this information here in hopes of getting it fixed in the upstream package.
I ran into a problem while waiting for the user to approve the application during the OAuth2 process. It was inconsistent and started happening only after I updated the Jira version (Data Center from 9.12 to 11.3).
While the
HttpListeneris supposed to be waiting for the user to response, on this line:var httpListenerContext = await httpListener.GetContextAsync().ConfigureAwait(false);This exception was thrown immediately, before the user has a chance to do anything.
System.Net.HttpListenerException (995): The I/O operation has been aborted because of either a thread exit or an application request.I am using the
LocalhostCodeReceiverclass.I thought it was a problem with Jira, due to the upgrade, but I tracked the problem down to this line in
UriHttpListenerExtensions:var listenTask = Task.Factory.StartNew(..., cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default).ConfigureAwait(false);If I replaced
LongRunningwithNone(the default), orTask.Run, then the problem went away.I've found some documentation that
Task.Factory.StartNewshould not be used withTaskCreationOptions.LongRunningin many cases.I'm not sure why it wasn't a problem with the previous version of Jira and only started happening now.
I was able to workaround this problem in my own application, but I'm adding this information here in hopes of getting it fixed in the upstream package.