Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
8b400447
Unverified
Commit
8b400447
authored
Jun 22, 2022
by
liuzhe-lz
Committed by
GitHub
Jun 22, 2022
Browse files
Fix the bug that tuner init error does not cause ERROR state (#4953)
parent
45af1d6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
5 deletions
+25
-5
ts/nni_manager/core/tuner_command_channel/websocket_channel.ts
...i_manager/core/tuner_command_channel/websocket_channel.ts
+25
-5
No files found.
ts/nni_manager/core/tuner_command_channel/websocket_channel.ts
View file @
8b400447
...
...
@@ -47,7 +47,7 @@ export function serveWebSocket(ws: WebSocket): void {
}
class
WebSocketChannelImpl
implements
WebSocketChannel
{
private
deferredInit
:
Deferred
<
void
>
=
new
Deferred
<
void
>
();
private
deferredInit
:
Deferred
<
void
>
|
null
=
new
Deferred
<
void
>
();
private
emitter
:
EventEmitter
=
new
EventEmitter
();
private
heartbeatTimer
!
:
NodeJS
.
Timer
;
private
serving
:
boolean
=
false
;
...
...
@@ -56,8 +56,13 @@ class WebSocketChannelImpl implements WebSocketChannel {
public
setWebSocket
(
ws
:
WebSocket
):
void
{
if
(
this
.
ws
!==
undefined
)
{
logger
.
error
(
'
A second client is trying to connect
'
);
ws
.
close
(
4030
,
'
Already serving a tuner.
'
);
logger
.
error
(
'
A second client is trying to connect.
'
);
ws
.
close
(
4030
,
'
Already serving a tuner
'
);
return
;
}
if
(
this
.
deferredInit
===
null
)
{
logger
.
error
(
'
Connection timed out.
'
);
ws
.
close
(
4080
,
'
Timeout
'
);
return
;
}
...
...
@@ -72,11 +77,26 @@ class WebSocketChannelImpl implements WebSocketChannel {
this
.
heartbeatTimer
=
setInterval
(
this
.
heartbeat
.
bind
(
this
),
heartbeatInterval
);
this
.
deferredInit
.
resolve
();
this
.
deferredInit
=
null
;
}
public
init
():
Promise
<
void
>
{
logger
.
debug
(
this
.
ws
===
undefined
?
'
Waiting connection...
'
:
'
Initialized.
'
);
return
this
.
deferredInit
.
promise
;
if
(
this
.
ws
===
undefined
)
{
logger
.
debug
(
'
Waiting connection...
'
);
// TODO: This is a quick fix. It should check tuner's process status instead.
setTimeout
(()
=>
{
if
(
this
.
deferredInit
!==
null
)
{
const
msg
=
'
Tuner did not connect in 10 seconds. Please check tuner (dispatcher) log.
'
;
this
.
deferredInit
.
reject
(
new
Error
(
'
tuner_command_channel:
'
+
msg
));
this
.
deferredInit
=
null
;
}
},
10000
);
return
this
.
deferredInit
!
.
promise
;
}
else
{
logger
.
debug
(
'
Initialized.
'
);
return
Promise
.
resolve
();
}
}
public
async
shutdown
():
Promise
<
void
>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment