Invalid response from Get() when an EF crash happens
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
- ASP.NET Core OData 8.0.12
- This seems like the same issue: https://github.com/OData/WebApi/issues/2704
I have a simple controller with a Get method, which reads from the database. The EntityFramework model had a bug (column was null). When reading, an exception was raised:
Microsoft.AspNetCore.Server.Kestrel[13]
... An unhandled exception was thrown by the application.
System.InvalidCastException: Column 'company_id' is null.
This causes the OData library to:
- Return a 200
- With a partially complete body
- Json is OK
- Response cuts off mid stream when the exception is raised
Data Model
class User {
public int Id {get; set;}
public int CompanyId { get; set; } // this should have been int?
}
Request/Response
curl -v localhost:5279/odata/v1/Users
* Trying 127.0.0.1:5279...
* Connected to localhost (127.0.0.1) port 5279 (#0)
> GET /odata/v1/Users HTTP/1.1
> Host: localhost:5279
> User-Agent: curl/7.86.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: application/json; odata.metadata=minimal; odata.streaming=true; charset=utf-8
< Date: Wed, 22 Mar 2023 08:01:24 GMT
< Server: Kestrel
< Transfer-Encoding: chunked
< OData-Version: 4.0
<
* transfer closed with outstanding read data remaining
* Closing connection 0
curl: (18) transfer closed with outstanding read data remaining
{
"@odata.context":"http://localhost:5279/odata/v1/$metadata#Users",
"value": [
{object-1},
{object-2}
// <-- crash happened here, content stops after last `}`
Expected behavior
- An HTTP_500 error should be raised
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the controller's Get method and reproduce the request against the EF model where CompanyId is non-nullable while the database column is null. Trace how the OData response is streamed after the InvalidCastException. Done means the failed request returns HTTP 500 instead of a 200 with a truncated JSON body.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100