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

got "incorrect header check" when invoke pako.inflate during websocket test #594

Closed
wallenZhao2046 opened this issue Apr 21, 2018 · 7 comments

Comments

@wallenZhao2046
Copy link

I am executing a websocket testing using K6.
when handling ws response, I need to inflate the content. and I tried to use pako to do that.
The following is my script. I found pako can't deflate string and inflate either.
I tried the same code in node.js, fount it worked well. Is there anything wrong?

import ws from "k6/ws";
import { check } from "k6";
import pako from './pako.js';

export default function() {
  var url = "ws://api.xxx.pro/ws";
  var params = { "tags": { "my_tag": "hello" } };
  var res = ws.connect(url, params, function(socket) {
    socket.on('open', function() {
      socket.send('WebSocket rocks');

     //begin--------
     // the following code is to test whether pako working in K6
     let data = { ping: "12345678"};
     console.log(JSON.stringify(data));
     let binStr = pako.deflate(JSON.stringify(data), {to:'string'});
     console.log(binStr);
     let text = pako.inflate(binStr, {
            to: 'string'
     });
     //end: ------------

    });

    socket.on('message', function(data) {
      // .....
    }); 

the error message is

INFO[0004] !!!!!!!

ERRO[0004] incorrect header check
	at inflate (/Users/zh/workspace/test_files/k6_files/pako_out.js:803:45(24))
	at /Users/zh/workspace/test_files/k6_files/ws_base_test.js:24:50(76)
@na-- na-- added bug and removed bug labels Apr 22, 2018
@na--
Copy link
Member

na-- commented Apr 22, 2018

This seems like it may be an issue with the bower version of the pako library itself. Executing bower install pako and then this script with k6:

import pako from './bower_components/pako/dist/pako.js';

export default function () {
    let data = { ping: "12345678" };

    let json = JSON.stringify(data);
    console.log(json);

    let binStr = pako.deflate(json);
    console.log(binStr);

    let text = pako.inflate(binStr);
    console.log(text);

    console.log(String.fromCharCode.apply(null, text));
}

works as expected and gives me:

INFO[0000] {"ping":"12345678"}                          
INFO[0003] 120,156,171,86,42,200,204,75,87,178,82,50,52,50,54,49,53,51,183,80,170,5,0,54,213,5,13 
INFO[0003] 123,34,112,105,110,103,34,58,34,49,50,51,52,53,54,55,56,34,125 
INFO[0003] {"ping":"12345678"}

As soon as I try to add {to:'string'} I get the error you mention and using raw: true as suggested here just gives me other errors.

@wallenZhao2046
Copy link
Author

wallenZhao2046 commented Apr 25, 2018

@na-- It works well here. Thanks a lot ! By the way, I got a reply message when I connected to a websocket server, and I printed it in console got a strang string code like "�V*��KW�245215�0145�0�����". How can I uncompress it? Would you please give me any idea?

@na--
Copy link
Member

na-- commented Apr 25, 2018

Sorry, I'm not sure what the reason is, maybe the server just uses the websockets to send some sort of binary data? In any case, that discussion is something that's more suited to the #support channel of the k6 slack, so I'm closing this issue for now.

@na-- na-- closed this as completed Apr 25, 2018
@wallenZhao2046
Copy link
Author

@na-- You are right. This issue is not a bug. Thanks for your reply.

@na--
Copy link
Member

na-- commented May 2, 2018

As seen here, it seems like this could indeed be a bug in the goja runtime or somewhere in the JavaScript stack (babel, core.js/etc.), so I'm reopening this issue.

@mstoykov
Copy link
Contributor

mstoykov commented Sep 8, 2021

The error in StackOverflow would probably be as data is a string but after #1841 it should now be possible to get it as ByteArray and use that?

@mstoykov
Copy link
Contributor

I am closing this as the error that was provided in the original report is no longer happening since k6 v0.26.2 but was present up to v0.25.1.

This likely was fixed by a goja update at some point and we just didn't notice

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

No branches or pull requests

3 participants