Skip to content

Fix HTTP context disposal race in Lecti selector deferred task#63

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-premature-object-disposal
Draft

Fix HTTP context disposal race in Lecti selector deferred task#63
Copilot wants to merge 2 commits intomainfrom
copilot/fix-premature-object-disposal

Conversation

Copy link
Copy Markdown

Copilot AI commented Nov 10, 2025

The deferred task in Lecti/Selector.cs captured closures over HTTP context objects that are disposed after request completion, causing access violations when the task executes asynchronously.

Changes

  • Capture IP address, target ID, and namespace as local variables before queuing the deferred task
  • Deferred task lambda now references captured values instead of disposed context objects
// Before: captured references to context objects
async Task Task(CancellationToken ct, Repositories repos) {
    var data = new PluginData {
        Key = context.Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(),
        Value = context.Target.Id.ToString(),
        Namespace = stk.Identity.OriginManifest.Name,
    };
    ...
}

// After: capture values first
var ipAddress = context.Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
var targetId = context.Target.Id.ToString();
var pluginNamespace = stk.Identity.OriginManifest.Name;

async Task Task(CancellationToken ct, Repositories repos) {
    var data = new PluginData {
        Key = ipAddress,
        Value = targetId,
        Namespace = pluginNamespace,
    };
    ...
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Fix premature object disposal on objs in deferred tasks</issue_title>
<issue_description></issue_description>

<agent_instructions>Appears on the Lecti selector deferred task, for the HTTP object</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: FT111 <40067386+FT111@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix premature object disposal in deferred tasks Fix HTTP context disposal race in Lecti selector deferred task Nov 10, 2025
Copilot AI requested a review from FT111 November 10, 2025 14:40
Base automatically changed from add-dynamic-cache to main November 13, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants