Skip to content

Commit

Permalink
[Foundation] Remove workaround for broken thread pool in Mono. Fixes #…
Browse files Browse the repository at this point in the history
…7080. (#17082)

Completely remove a workaround for an issue with the thread pool in Mono.
We've previously turned this workaround off by default, and we got no reports
of any problems.

Fixes #7080.
  • Loading branch information
rolfbjarne authored Dec 21, 2022
1 parent 376081f commit 322ce2d
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/Foundation/NSUrlSessionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Net;
Expand Down Expand Up @@ -173,7 +174,7 @@ public NSUrlSessionHandler (NSUrlSessionConfiguration configuration)
inflightRequests = new Dictionary<NSUrlSessionTask, InflightData> ();
}

#if !MONOMAC && !__WATCHOS__
#if !MONOMAC && !__WATCHOS__ && !NET8_0

void AddNotification ()
{
Expand Down Expand Up @@ -223,7 +224,7 @@ void RemoveInflightData (NSUrlSessionTask task, bool cancel = true)
data.Dispose ();
inflightRequests.Remove (task);
}
#if !MONOMAC && !__WATCHOS__
#if !MONOMAC && !__WATCHOS__ && !NET8_0
// do we need to be notified? If we have not inflightData, we do not
if (inflightRequests.Count == 0)
RemoveNotification ();
Expand All @@ -239,7 +240,7 @@ void RemoveInflightData (NSUrlSessionTask task, bool cancel = true)
protected override void Dispose (bool disposing)
{
lock (inflightRequestsLock) {
#if !MONOMAC && !__WATCHOS__
#if !MONOMAC && !__WATCHOS__ && !NET8_0
// remove the notification if present, method checks against null
RemoveNotification ();
#endif
Expand Down Expand Up @@ -328,21 +329,37 @@ public NSUrlSessionHandlerTrustOverrideForUrlCallback? TrustOverrideForUrl {
trustOverrideForUrl = value;
}
}
#if !NET8_0
// we do check if a user does a request and the application goes to the background, but
// in certain cases the user does that on purpose (BeingBackgroundTask) and wants to be able
// to use the network. In those cases, which are few, we want the developer to explicitly
// bypass the check when there are not request in flight
bool bypassBackgroundCheck = true;
#endif

#if !XAMCORE_5_0
[EditorBrowsable (EditorBrowsableState.Never)]
#if NET8_0
[Obsolete ("This property is ignored.")]
#else
[Obsolete ("This property will be ignored in .NET 8.")]
#endif
public bool BypassBackgroundSessionCheck {
get {
#if NET8_0
return true;
#else
return bypassBackgroundCheck;
#endif
}
set {
#if !NET8_0
EnsureModifiability ();
bypassBackgroundCheck = value;
#endif
}
}
#endif // !XAMCORE_5_0

public CookieContainer? CookieContainer {
get {
Expand Down Expand Up @@ -497,7 +514,7 @@ protected override async Task<HttpResponseMessage> SendAsync (HttpRequestMessage
var inflightData = new InflightData (request.RequestUri?.AbsoluteUri!, cancellationToken, request);

lock (inflightRequestsLock) {
#if !MONOMAC && !__WATCHOS__
#if !MONOMAC && !__WATCHOS__ && !NET8_0
// Add the notification whenever needed
AddNotification ();
#endif
Expand Down

4 comments on commit 322ce2d

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.