Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading container data occasionally returns a 401 Unauthorized response. #287

Closed
fuzzzerd opened this issue Jun 7, 2023 · 2 comments · Fixed by #288
Closed

Loading container data occasionally returns a 401 Unauthorized response. #287

fuzzzerd opened this issue Jun 7, 2023 · 2 comments · Fixed by #288
Assignees
Labels
bug Something isn't working
Milestone

Comments

@fuzzzerd
Copy link
Owner

fuzzzerd commented Jun 7, 2023

Describe the bug

Loading container data occasionally returns a 401 Unauthorized response.

Steps To Reproduce

Load a lot of container data in a short period of time, and observe that some return a 401 Unauthorized

Expected behavior

The binary data to be returned with an HTTP 200 response code (or sometimes a 302 response

fmdata version

v5.0.0

Additional context

Relevant area:

protected override async Task<byte[]> GetContainerOnClient(string containerEndPoint)
{
// build the request message
var requestMessage = new HttpRequestMessage(HttpMethod.Get, containerEndPoint);
// include auth token on the request
requestMessage.Headers.Authorization = _authHeader;
// send the request out
var data = await Client.SendAsync(requestMessage).ConfigureAwait(false);
// read the bytes as a stream
var dataBytes = await data.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
return dataBytes;
}

Observed as:

401 Unauthorized

IIS Log Snip:

2023-06-07 22:02:39 127.0.0.1 GET /Streaming_SSL/Additional_1/[redacted].png RCType=RCFileProcessor&Redirect&X-ARR-CACHE-HIT=0&X-ARR-LOG-ID=[redacted]&SERVER-STATUS=401 443 - 127.0.0.1 FMData.Rest/5.0.0+4cf2ece2fb68fe28090ec45fceeb0d74bf984cb3 - 401 0 0 36

Others on the Claris forms have added [special retry logic for this scenario.](You can get a 401 error if the cookie jar wasn't set up properly; I haven't seen a 400 error in this particular case. I had to put some code into fmPDA to handle the 401 and do a retry to help resolve the issue. It's unfortunately one of the less smooth parts of how the Data API behaves.)

You can get a 401 error if the cookie jar wasn't set up properly; I haven't seen a 400 error in this particular case. I had to put some code into fmPDA to handle the 401 and do a retry to help resolve the issue. It's unfortunately one of the less smooth parts of how the Data API behaves.

@fuzzzerd fuzzzerd added the bug Something isn't working label Jun 7, 2023
@fuzzzerd fuzzzerd added this to the v5.1.0 milestone Jun 7, 2023
@fuzzzerd
Copy link
Owner Author

fuzzzerd commented Jun 8, 2023

This seems NOT to happen with a simple

var client = new FileMakerRestClient();
var data = await client.SendAsync(...find request)
await client.ProcessContainers(data);

and seems to have something to do with being added to the ASP.NET DI system, possibly due to cookie sharing when, see also: tmenier/Flurl#506, dotnet/runtime#1904

@fuzzzerd
Copy link
Owner Author

fuzzzerd commented Jun 9, 2023

FileMaker Container data urls are secured by a Cookie, that is set on First access of the URL. We're using managed IHttpClientFactory to generate HttpClients and those share a CookieContainer which is likely getting reset and/or mismatched across outbound requests. Possibly due to the default lifetime of the HttpClientHandler.

As noted above, newing up a client directly and hammering it with repeated requests to load data and then associated container data does NOT produce this error ever.

@fuzzzerd fuzzzerd self-assigned this Jun 9, 2023
@fuzzzerd fuzzzerd linked a pull request Jun 9, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant