Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5a4f763
Fix port conflict error message and cleanup on failure
beena352 Apr 3, 2026
fbe3b22
Fix port conflict to use HostPort() in error message
beena352 Apr 6, 2026
e7a0b93
Handle WSAEADDRINUSE in port conflict error
beena352 Apr 6, 2026
e956563
fix test
beena352 Apr 7, 2026
9cf93d4
Merge branch 'feature/wsl-for-apps' into user/beenachauhan/fix-port-c…
beena352 Apr 7, 2026
a9945f9
Add cleanup
beena352 Apr 7, 2026
d07eb74
Merge branch 'user/beenachauhan/fix-port-conflict-error-message' of h…
beena352 Apr 7, 2026
6f60b8c
Localize port-conflict error
beena352 Apr 8, 2026
f867989
Merge branch 'feature/wsl-for-apps' of https://github.com/microsoft/W…
beena352 Apr 9, 2026
1c6cc25
Merge branch 'feature/wsl-for-apps' of https://github.com/microsoft/W…
beena352 Apr 9, 2026
d09c8b5
Fix port conflict error message and cleanup on failure
beena352 Apr 3, 2026
4b02ca5
Fix port conflict to use HostPort() in error message
beena352 Apr 6, 2026
7588ba3
Handle WSAEADDRINUSE in port conflict error
beena352 Apr 6, 2026
e22f6a1
fix test
beena352 Apr 7, 2026
1051ef2
Add cleanup
beena352 Apr 7, 2026
6bf5408
Localize port-conflict error
beena352 Apr 8, 2026
3c78d42
Add IPv6 brackets to port conflict error
beena352 Apr 9, 2026
bcb91cf
resolve conflicts
beena352 Apr 9, 2026
aa39cd8
resolve conflicts
beena352 Apr 10, 2026
d1b0d15
Address feedback
beena352 Apr 13, 2026
971ea9f
validating the complete error message
beena352 Apr 13, 2026
6e3f21b
Verify container rm result
beena352 Apr 13, 2026
76ae9ca
resolve conflicts
beena352 Apr 13, 2026
1f03aa7
address copilot feedback
beena352 Apr 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/windows/wslc/services/ContainerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,16 @@ int ContainerService::Run(Session& session, const std::string& image, ContainerO
{
// Create the container
auto runningContainer = CreateInternal(session, image, runOptions);
runningContainer.SetDeleteOnClose(false);
auto& container = runningContainer.Get();

// Start the created container
WSLCContainerStartFlags startFlags{};
WI_SetFlagIf(startFlags, WSLCContainerStartFlagsAttach, !runOptions.Detach);
THROW_IF_FAILED(container.Start(startFlags, nullptr)); // TODO: Error message, detach keys

// Disable auto-delete only after successful start
runningContainer.SetDeleteOnClose(false);

// Handle attach if requested
if (WI_IsFlagSet(startFlags, WSLCContainerStartFlagsAttach))
{
Expand Down
31 changes: 20 additions & 11 deletions src/windows/wslcsession/WSLCContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,12 +1274,10 @@ std::unique_ptr<WSLCContainerImpl> WSLCContainerImpl::Open(
{
auto allocation = virtualMachine.TryAllocatePort(e.VmPort, e.Family, e.Protocol);

THROW_HR_IF_MSG(
THROW_HR_WITH_USER_ERROR_IF(
HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS),
!allocation,
"Port %hu is in use, cannot open container %hs",
e.VmPort,
dockerContainer.Id.c_str());
std::format(L"Port {} is already in use, cannot open container {}", e.VmPort, dockerContainer.Id),
!allocation);

inserted.VmMapping.AssignVmPort(allocation);
}
Expand Down Expand Up @@ -1443,20 +1441,31 @@ void WSLCContainerImpl::MapPorts()
auto allocatedPort =
m_virtualMachine.TryAllocatePort(e.ContainerPort, e.VmMapping.BindAddress.si_family, e.VmMapping.Protocol);

THROW_HR_IF_MSG(
THROW_HR_WITH_USER_ERROR_IF(
HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS),
!allocatedPort,
"Port %hu is in use, cannot start container %hs",
e.ContainerPort,
m_id.c_str());
std::format(L"Port {} is already in use, cannot start container {}", e.ContainerPort, m_id),
!allocatedPort);

e.VmMapping.AssignVmPort(allocatedPort);

allocatedPorts.emplace(e.ContainerPort, allocatedPort);
}
}

m_virtualMachine.MapPort(e.VmMapping);
try
{
m_virtualMachine.MapPort(e.VmMapping);
}
catch (const wil::ResultException& ex)
{
if (ex.GetErrorCode() == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS))
{
THROW_HR_WITH_USER_ERROR(
HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS),
std::format(L"Port {} is already in use, cannot start container {}", e.ContainerPort, m_id));
}
throw;
}
}
}

Expand Down