AsyncWebserver_Teensy returns invalid status line

Problem

My teensy is connected to 4 Serial devices and I use the Webserver provide access to them over a local network. I have a Raspberry Pi that is requesting data from the Webserver in multiple threads. It sometimes happens that the requests to the webserver are simultaneously (within 1 ms). Roughly 5% of the time the webserver send an invalid status line back. E.g. (0xb0 ce 00 20 b0 ce 00 20)200 OK instead of HTTP/1.1 200 OK. The string 200 OK is always there and the payload is also intact, just HTTP/1.1 is scrambled. I tested this with wireshark. This causes an HttpRequestException: Received an invalid status line: '?? ?? 200 OK'. in my C# application on the RPi (also on my local machine I just for development).

I tried to find the bug in the Webserver Code but could not find it. I only found the code where the header gets assembled

https://github.com/khoih-prog/AsyncWebServer_Teensy41/blob/main/src/AsyncWebResponses_Teensy41.cpp#L265

Workaround

I want to do a workaround in the C# (.Net 6) Application by catching the Exception and look at the status line. If it contains 200 OK it is valid. But I cannot access response in the following code:

HttpResponseMessage response;
try
{
    response = await client.GetAsync(url);
}
catch (HttpRequestException exc)
{
    Console.WriteLine($"Status Code: {exc.StatusCode}");
    Console.WriteLine($"Request error: {exc.ToString()}");
    Console.WriteLine($"Request error: {exc.Message}");
}

Output:

Request error: System.Net.Http.HttpRequestException: Received an invalid status line: '►? ►?  200 OK'.
   at System.Net.Http.HttpConnection.ParseStatusLine(ReadOnlySpan`1 line, HttpResponseMessage response)
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Program.readControllerVerion(String url) in C:XXXSANDBOXConsoleApp4(.NET6.0)Program.cs:line 62
Request error: Received an invalid status line: '►? ►?  200 OK'.

I could look if exc.message contains Received an invalid status line: and 200 OK, but I’m not sure if that is the best way.

TCP

I noticed that there is a TCP Connection opened and closed for every http request even if I use one HttpClient per thread. It seems that the TCP Connections are overlapping each other. Maybe that is causing the Teensy to messup the status line. Can I force the HTTP Client to reuse the TCP Connection?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật