Skip to content

Commit

Permalink
fix: abnormal websocket closure post ccm (#1727)
Browse files Browse the repository at this point in the history
Co-authored-by: madhavilosetty-intel <[email protected]>
  • Loading branch information
graikhel-intel and madhavilosetty-intel authored Aug 2, 2024
1 parent d568ce1 commit 755aa02
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/DataProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class DataProcessor {
}
}
this.logger.debug(
`Device ${clientId}` +
`Device ${clientId} ` +
`wsman response ${statusCode} ${resolveValue ? 'resolved' : 'rejected'}: ` +
`${JSON.stringify(clientMsg.payload, null, '\t')}`
)
Expand Down
2 changes: 1 addition & 1 deletion src/stateMachines/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ export class Activation {
'Set activation status'

],
target: 'UPDATE_CREDENTIALS'
target: 'DELAYED_TRANSITION'
},
{
guard: 'isDeviceClientModeActivated',
Expand Down
2 changes: 1 addition & 1 deletion src/stateMachines/deactivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class Deactivation {
unauthCount: 0,
xmlMessage: input.xmlMessage,
errorMessage: input.errorMessage,
statusMessage: input.statusMessage,
statusMessage: '',
tenantId: input.tenantId,
httpHandler: new HttpHandler()
}),
Expand Down
13 changes: 12 additions & 1 deletion src/stateMachines/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { sendParent, setup } from 'xstate'
import { HttpHandler } from '../HttpHandler.js'
import { devices } from '../devices.js'
import { type HttpZResponseModel } from 'http-z'
import Logger from '../Logger.js'

const httpHandler = new HttpHandler()
export interface ErrorContext {
Expand All @@ -20,6 +21,8 @@ interface ErrorEvent {
}

export class Error {
logger: Logger

addAuthorizationHeader = ({ context }: { context: ErrorContext }): void => {
const { message, clientId } = context
const clientObj = devices[clientId]
Expand All @@ -38,6 +41,7 @@ export class Error {
resetAuthCount = ({ context }: { context: ErrorContext }): void => {
if (devices[context.clientId] != null) {
devices[context.clientId].unauthCount = 0
this.logger.silly(`Reset unauthCount of ${context.clientId} to 0`)
}
}

Expand Down Expand Up @@ -70,7 +74,10 @@ export class Error {
resetAuthCount: this.resetAuthCount
}
}).createMachine({
context: ({ input }) => ({ message: input.message, clientId: input.clientId }),
context: ({ input }) => {
this.logger.silly(`${JSON.stringify(input.message)}`)
return { message: input.message, clientId: input.clientId }
},
id: 'error-machine',
initial: 'ERRORED',
states: {
Expand Down Expand Up @@ -117,4 +124,8 @@ export class Error {
}
}
})

constructor() {
this.logger = new Logger('Error_State_Machine')
}
}
4 changes: 2 additions & 2 deletions src/stateMachines/unconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export class Unconfiguration {
src: 'errorMachine',
id: 'error-machine',
input: ({ context, event }) => ({
message: event.output,
message: event.error,
clientId: context.clientId
}),
onDone: 'ENUMERATE_ETHERNET_PORT_SETTINGS'
Expand Down Expand Up @@ -1086,6 +1086,6 @@ export class Unconfiguration {
this.configurator = new Configurator()
this.validator = new Validator(new Logger('Validator'), this.configurator)
this.dbFactory = new DbCreatorFactory()
this.logger = new Logger('Activation_State_Machine')
this.logger = new Logger('Unconfiguration_State_Machine')
}
}

0 comments on commit 755aa02

Please sign in to comment.