Repository navigation
Drop redundant fixed in HttpSys SetDataChunkWithPinnedData - #66578
Conversation
|
Thanks for your PR, @unsafePtr. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
@BrennanConroy , @halter73 . Is the change useless because Kestrel is used mainly? Shall I close the PR? |
|
I wouldn't say useless, but it doesn't really improve much. Really, we should either pass in a pointer so it's clearer the caller should pin the bytes, or inline the method so it's easier to see the lifetime of the pinned bytes. |
SetDataChunkWithPinnedData took a span whose pinning was an unwritten caller contract. Keep one copy of each constant on the pinned object heap and build the HTTP_DATA_CHUNK once, so the literal call sites just assign a ready-made chunk. The remaining caller derives its pointer next to the GCHandle it allocates, making the pin and its lifetime visible in one place.
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. |
|
/ba-g unrelated |
|
Thanks @unsafePtr |
|
✅ No documentation PR was created. Confidence that documentation is needed: 3% Confident no docs needed: pure internal cleanup removing a redundant fixed block in HttpSys helpers. Documentation surfaces considered
|
Description
Drops the
fixed (byte* ptr = bytes)block from the twoSetDataChunkWithPinnedDatahelpers in HttpSys. The pin was redundant: the implementation capturesptrintochunk.pBufferfor HTTP.SYS to read later, so thefixedscope ends before the value is consumed. Safety always relied on the caller keeping the data alive, not thefixedblock — the helper's name reflects that contract.All 5 call sites verified
ResponseBody.cs:196,:248,:252Helpers.ChunkTerminator/CRLF"...\r\n..."u8— embedded in assembly RVA section, never movedResponseBody.cs:275handle.AddrOfPinnedObject() + offsetGCHandle.Alloc(..., Pinned), freed byFreeDataBuffersResponseStreamAsyncResult.cs:70,:134Helpers.CRLFUTF-8 literals (
"..."u8) live in assembly metadata, not on the GC heap. The GCHandle-pinned site keeps the buffer alive for the lifetime of the chunk's use.Behavior preservation
fixed (byte* ptr = bytes)returnsnullwhenbytes.IsEmpty, regardless of how the span was constructed.MemoryMarshal.GetReference(bytes)does not — per its documentation, for an empty span built from a non-null pointer (e.g. a zero-lengthArraySegmentof a GCHandle-pinned array) it returns a non-null ref. Thebytes.IsEmpty ? null : ...guard preserves the original null-on-empty semantic.Consistency with existing code
ResponseStreamAsyncResult.cs:80already uses the equivalent pattern for an externally-pinned array —(void*)Marshal.UnsafeAddrOfPinnedArrayElement(...)with nofixedblock. The two helpers were the outliers in this file. This change aligns them with that neighboring pattern.No behavior change at runtime; pure cleanup.