Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createClient() throws websocket "Parse Error: Expected HTTP/" error #27

Closed
smartintruesdell opened this issue Sep 11, 2020 · 3 comments
Closed

Comments

@smartintruesdell
Copy link

smartintruesdell commented Sep 11, 2020

Kerbal Space Program version 1.8.1
KRPC version 0.4.8
krpc-node version 4.0.2
node 14.10.1

I'm running into an issue where calling createClient() is immediately throwing a websocket error:

error: Error: Parse Error: Expected HTTP/
at Socket.socketOnData (_http_client.js:509:22)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:307:12)
at readableAddChunk (_stream_readable.js:282:9)
at Socket.Readable.push (_stream_readable.js:221:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
bytesParsed: 0,
code: 'HPE_INVALID_CONSTANT',
reason: 'Expected HTTP/',

package.json

{
  "name": "krpc-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node ./index.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "krpc-node": "^4.0.2"
  }
}

index.js

var RPC = require('krpc-node');

var rpcClient;

RPC.createClient()
  .then(function(client) {
    rpcClient = client;
    return client;
  })
  .then(function(client) {
    return client.close();
  })
  .catch(function(err) {
    rpcClient && rpcClient.close();
    throw err;
  });

Am I missing a setup step? I didn't see anything in the examples that I'm doing wrong in this test script.

My searches seem to suggest this is an issue with a HEAD call returning a response body?

Here's the complete error:

> [email protected] start mypath\krpc-test
> node ./index.js

events.js:305
    throw err; // Unhandled 'error' event
    ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. (ErrorEvent {
  target: WebSocket {
    _events: [Object: null prototype] {
      error: [Function],
      close: [Function],
      message: [Function],
      open: [Function]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    readyState: 2,
    protocol: '',
    _binaryType: 'arraybuffer',
    _finalize: [Function: bound finalize],
    _closeFrameReceived: false,
    _closeFrameSent: false,
    _closeMessage: '',
    _closeTimer: null,
    _finalized: true,
    _closeCode: 1006,
    _extensions: {},
    _isServer: false,
    _receiver: null,
    _sender: null,
    _socket: null,
    _error: null,
    url: 'ws://127.0.0.1:50000',
    _req: null,
    [Symbol(kCapture)]: false
  },
  type: 'error',
  message: 'Parse Error: Expected HTTP/',
  error: Error: Parse Error: Expected HTTP/
      at Socket.socketOnData (_http_client.js:509:22)
      at Socket.emit (events.js:314:20)
      at addChunk (_stream_readable.js:307:12)
      at readableAddChunk (_stream_readable.js:282:9)
      at Socket.Readable.push (_stream_readable.js:221:10)
      at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
    bytesParsed: 0,
    code: 'HPE_INVALID_CONSTANT',
    reason: 'Expected HTTP/',
    rawPacket: <Buffer 67 08 01 12 63 4d 65 72 67 65 20 61 6e 20 75 6e 6b 6e 6f 77 6e 20 66 69 65 6c 64 20 6f 66 20 65 6e 64 2d 67 72 6f 75 70 20 74 61 67 2c 20 69 6e 64 69 ... 54 more bytes>
  }
})
    at EventEmitter.emit (events.js:303:17)
    at WebSocket.client.rpc.socket.onerror (mypath\krpc-test\node_modules\krpc-node\lib\client.js:272:28)
    at WebSocket.onError (mypath\krpc-test\node_modules\ws\lib\event-target.js:128:16)
    at WebSocket.emit (events.js:314:20)
    at WebSocket.finalize (mypath\krpc-test\node_modules\ws\lib\websocket.js:185:12)
    at ClientRequest.<anonymous> (mypath\krpc-test\node_modules\ws\lib\websocket.js:635:10)
    at ClientRequest.emit (events.js:314:20)
    at Socket.socketOnData (_http_client.js:516:9)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:307:12) {
  code: 'ERR_UNHANDLED_ERROR',
  context: ErrorEvent {
    target: WebSocket {
      _events: [Object: null prototype] {
        error: [Function: onError] { _listener: [Function (anonymous)] },
        close: [Function: onClose] { _listener: [Function (anonymous)] },
        message: [Function: onMessage] { _listener: [Function (anonymous)] },
        open: [Function: onOpen] { _listener: [Function (anonymous)] }
      },
      _eventsCount: 4,
      _maxListeners: undefined,
      readyState: 2,
      protocol: '',
      _binaryType: 'arraybuffer',
      _finalize: [Function: bound finalize],
      _closeFrameReceived: false,
      _closeFrameSent: false,
      _closeMessage: '',
      _closeTimer: null,
      _finalized: true,
      _closeCode: 1006,
      _extensions: {},
      _isServer: false,
      _receiver: null,
      _sender: null,
      _socket: null,
      _error: null,
      url: 'ws://127.0.0.1:50000',
      _req: null,
      [Symbol(kCapture)]: false
    },
    type: 'error',
    message: 'Parse Error: Expected HTTP/',
    error: Error: Parse Error: Expected HTTP/
        at Socket.socketOnData (_http_client.js:509:22)
        at Socket.emit (events.js:314:20)
        at addChunk (_stream_readable.js:307:12)
        at readableAddChunk (_stream_readable.js:282:9)
        at Socket.Readable.push (_stream_readable.js:221:10)
        at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
      bytesParsed: 0,
      code: 'HPE_INVALID_CONSTANT',
      reason: 'Expected HTTP/',
      rawPacket: Buffer(104) [Uint8Array] [
        103,   8,   1,  18,  99,  77, 101, 114, 103, 101,  32,  97,
        110,  32, 117, 110, 107, 110, 111, 119, 110,  32, 102, 105,
        101, 108, 100,  32, 111, 102,  32, 101, 110, 100,  45, 103,
        114, 111, 117, 112,  32, 116,  97, 103,  44,  32, 105, 110,
        100, 105,  99,  97, 116, 105, 110, 103,  32, 116, 104,  97,
        116,  32, 116, 104, 101,  32,  99, 111, 114, 114, 101, 115,
        112, 111, 110, 100, 105, 110, 103,  32, 115, 116,  97, 114,
        116,  45, 103, 114, 111, 117, 112,  32, 119,  97, 115,  32,
        109, 105, 115, 115,
        ... 4 more items
      ]
    }
  }
}
@smartintruesdell
Copy link
Author

I tried grabbing a CI build of krpc/krpc @ 0.4.9, to see if a newer version of the server would resolve this.

Unfortunately, it did not. I'm still seeing the same error from the initial comment.

I checked and found that I am able to connect using a Python client, so it looks like the server is accepting connections from other clients.

image

@smartintruesdell
Copy link
Author

I used the node debugger to step through what was happening in createClient() and it looks like the error is happening just as the websocket connection is initialized. So I made an even simpler test:

const Websocket = require('ws');

const socket = new Websocket('ws://localhost:50000');

This also blows up with the same error. This problem isn't with krpc-node, it's in krpc itself.

I'm going to go ahead and close this issue.

@smartintruesdell
Copy link
Author

Related issue is here: krpc/krpc#583

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant