OfficeDev / Office-Addin-Scripts

A set of scripts and packages that are consumed in Office add-ins projects.
MIT License
153 stars 93 forks source link

[patch] Ignore trailing \r in parsed processId #775

Closed apolakipso closed 1 year ago

apolakipso commented 1 year ago

In Windows, npm start often fails to start the dev server, logging The dev server is already running on port 3000, even though it's been stopped with npm stop before. Only the first npm stop call shows that it found a process id to stop, so the server is indeed being stopped correctly.

The issue is caused by getProcessIdsForPort() often returning [ 0 ] and interpreting it as there's a pid so the server is still running, since the line being parsed contains a trailing "\r" which breaks the check !== '0' in https://github.com/OfficeDev/Office-Addin-Scripts/blob/master/packages/office-addin-debugging/src/port.ts#L78

if (processId !== undefined && processId !== '0') {

Logging the parts being parsed in getProcessIdsForPort() shows this:

{
  protocol: 'TCP',
  localAddress: '[::1]:3000',
  foreignAddress: '[::1]:50300',
  status: 'TIME_WAIT',
  processId: '0\r'
}
{
  protocol: 'TCP',
  localAddress: '[::1]:3000',
  foreignAddress: '[::1]:50301',
  status: 'TIME_WAIT',
  processId: '0\r'
}
{
  protocol: 'TCP',
  localAddress: '[::1]:3000',
  foreignAddress: '[::1]:50302',
  status: 'TIME_WAIT',
  processId: '0\r'
}

processId.trim() fixes the check and can be called since we've already guarded against undefined before.

This PR does not impact command syntax or documentation. Testing has been done manually on Win32 (the change affects Windows only)

millerds commented 1 year ago

/azurepipelines run

azure-pipelines[bot] commented 1 year ago
Azure Pipelines successfully started running 1 pipeline(s).