@@ -154,24 +154,38 @@ export class MonitorManager extends CoreClientAware {
154154 async notifyUploadFinished ( board ?: Board , port ?: Port ) : Promise < Status > {
155155 this . isUploadInProgress = false ;
156156 let status : Status = Status . NOT_CONNECTED ;
157+ let monitorID ;
157158 // We have no way of knowing which monitor
158159 // to retrieve if we don't have this information.
159160 if ( board && port ) {
160- const monitorID = this . monitorID ( board , port ) ;
161+ monitorID = this . monitorID ( board , port ) ;
161162 const monitor = this . monitorServices . get ( monitorID ) ;
162163 // There's no monitor running there, bail
163164 if ( monitor ) {
164165 status = await monitor . start ( ) ;
165166 }
166167 }
167- await this . startQueuedServices ( ) ;
168+ await this . startQueuedServices ( monitorID ) ;
168169 return status ;
169170 }
170171
171- async startQueuedServices ( ) : Promise < void > {
172- // here we remove the first item as in all likelihood it's
173- // probably the port we used to perform an upload
174- const queued = this . startMonitorPendingRequests . slice ( 1 ) ;
172+ async startQueuedServices (
173+ monitorIDRelatedToUploadBoard ?: string // when upload initially requested
174+ ) : Promise < void > {
175+ let portDidChangeOnUpload = false ;
176+ if ( monitorIDRelatedToUploadBoard ) {
177+ portDidChangeOnUpload = ! [ ...this . monitorServices . keys ( ) ] . includes (
178+ monitorIDRelatedToUploadBoard
179+ ) ;
180+ }
181+ // if we no longer have a monitor service for the "board, port"
182+ // combination with which we called "notifyUploadStarted", we know
183+ // the port changed during upload, hence in our "startMonitorPendingRequests"
184+ // we'll have our "upload port', most likely at index 0.
185+ // We remove it, as there will no longer be a board using this "upload port"
186+ const queued = portDidChangeOnUpload
187+ ? this . startMonitorPendingRequests . slice ( 1 )
188+ : this . startMonitorPendingRequests ;
175189 this . startMonitorPendingRequests = [ ] ;
176190
177191 for ( const [ [ board , port ] , onFinish ] of queued ) {
0 commit comments