Skip to content

Commit

Permalink
fixed auto mode not trying tcp (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellpeck authored Oct 2, 2024
1 parent 7971ad5 commit bd8d0ea
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/flowr/server-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class FlowrServerSession implements FlowrSession {
this.state = 'connecting'
updateStatusBar()

this.connect(getConfig().get<ConnectionType>(Settings.ServerConnectionType, 'auto'))
const configType = getConfig().get<ConnectionType>(Settings.ServerConnectionType, 'auto')
this.connect(configType, configType)

// the first response will be flowR's hello message
return this.awaitResponse().then(r => {
Expand All @@ -58,12 +59,12 @@ export class FlowrServerSession implements FlowrSession {
this.connection?.destroy()
}

private connect(type: ConnectionType): void {
private connect(configType: ConnectionType, typeToUse: ConnectionType): void {
const host = getConfig().get<string>(Settings.ServerHost, 'localhost')
const port = getConfig().get<number>(Settings.ServerPort, 1042)
this.outputChannel.appendLine(`Connecting to flowR server using ${type} at ${host}:${port}`)
this.outputChannel.appendLine(`Connecting to flowR server using ${typeToUse} at ${host}:${port}`)
// if the type is auto, we still start with a (secure!) websocket connection first
this.connection = isWeb() ? new BrowserWsConnection(type !== 'websocket') : type == 'tcp' ? new TcpConnection() : new WsConnection(type !== 'websocket')
this.connection = isWeb() ? new BrowserWsConnection(typeToUse !== 'websocket') : typeToUse == 'tcp' ? new TcpConnection() : new WsConnection(typeToUse !== 'websocket')
this.connection.connect(host, port, () => {
this.state = 'connected'
updateStatusBar()
Expand All @@ -72,9 +73,9 @@ export class FlowrServerSession implements FlowrSession {
this.connection.on('error', e => {
this.outputChannel.appendLine(`flowR server error: ${(e as Error).message}`)

if(type == 'auto' && this.connection instanceof WsConnection) {
if(configType == 'auto' && this.connection instanceof WsConnection) {
// retry with tcp if we're in auto mode and the ws secure and normal ws connections failed
this.connect(this.connection.secure ? 'websocket' : 'tcp')
this.connect(configType, this.connection.secure ? 'websocket' : 'tcp')
} else {
this.state = 'inactive'
updateStatusBar()
Expand Down

0 comments on commit bd8d0ea

Please sign in to comment.