Specific PDF file causing internal server error. #450
Replies: 2 comments 8 replies
-
I'm a little confused by your description of the problem. On one hand you say that this problem occurs Right above the red marker is the line where you attempt to copy the content of the request to a memory stream. Isn't that the most likely culprit? Could it be that the PDF is exceedingly large and somehow it's causing an issue with copying the content? In addition to the PDF file being very large, could there be an issue where your VB.NET code is reading the content of the request faster than it's being streamed? I know this sounds far fetched, but I have heard of this situation before: here and here. In both of these cases, the developers were using Tcp NetworkStream so they probably don't directly apply to your situation. |
Beta Was this translation helpful? Give feedback.
-
To help us investigate further, I suggest you save the content of the inbound email to a file and upload to the private repo and that will allow me to run a unit test with the actual data that is posted to your controller. Here's a handy method I wrote for debugging purposes. It writes the HTTP headers and the payload of the request to text files. you invoke this method like so: await Utils.SaveRequest(Request, "DebuggingWeirdPdf").ConfigureAwait(false); public static async Task SaveRequest(HttpRequest request, string name)
{
try
{
// Check if file(s) already exist
var previousHeaderFiles = Directory.EnumerateFiles("C:\\Temp\\", $"{name}InboundHeaders*.txt").ToArray();
var previousPayloadFiles = Directory.EnumerateFiles("C:\\Temp\\", $"{name}InboundPayload*.txt").ToArray();
// Save the headers to a file
await File
.WriteAllTextAsync(
$"C:\\Temp\\{name}InboundHeaders{(previousHeaderFiles.Length + 1):00}.txt",
JsonConvert.SerializeObject(request.Headers, Formatting.Indented))
.ConfigureAwait(false);
// Save the payload to a file
await using var body = new MemoryStream();
await request.Body.CopyToAsync(body).ConfigureAwait(false);
body.Position = 0;
using var reader = new StreamReader(body);
var postedData = await reader.ReadToEndAsync().ConfigureAwait(false);
await File
.WriteAllTextAsync(
$"C:\\Temp\\{name}InboundPayload{(previousPayloadFiles.Length + 1):00}.txt",
postedData)
.ConfigureAwait(false);
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
} |
Beta Was this translation helpful? Give feedback.
-
Hello, (Me again!)
During our internal testing, we seem to have identified a PDF file that is causing our API endpoint to throw an internal server error (500) when calling "ParseInboundEmailWebhookAsync".
We have sent hundreds of emails with a plethora of attachments to test our email server over the past week and it works great especially with all PDF attachments, except this one. The file isn't corrupt and opens as normal in many PDF viewers too.
This is the current API code running when attempting to parse inbound web responses. I can confirm the code executes up till the yellow marker but never hits the red marker nor the exception block.
I can't attachment this PDF publicly as it is confidential but I can provide in private.
Am I missing something? Has this been reported before?
Beta Was this translation helpful? Give feedback.
All reactions