JMeter-WebSocketSampler icon indicating copy to clipboard operation
JMeter-WebSocketSampler copied to clipboard

Not to able to get websocket connection?any help

Open mittanareddy opened this issue 9 years ago • 13 comments

Thread Name: Thread Group 1-1 Sample Start: 2015-04-20 13:18:38 EDT Load time: 5010 Connect Time: 0 Latency: 0 Size in bytes: 0 Headers size in bytes: 0 Body size in bytes: 0 Sample Count: 1 Error Count: 1 Response code: Response message:

[Execution Flow]

  • Opening new connection
  • Using response message pattern ""
  • Using disconnect pattern ""
  • Waiting for the server connection for 5000 MILLISECONDS
  • Cannot connect to the remote server

[Variables]

  • Message count: 0

[Problems]

  • Unexpected error: null JMeter.plugins.functional.samplers.websocket.ServiceSocket.sendMessage(ServiceSocket.java:147) JMeter.plugins.functional.samplers.websocket.WebSocketSampler.sample(WebSocketSampler.java:116) org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434) org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261) java.lang.Thread.run(Unknown Source)

Response headers:

SampleResult fields: ContentType: DataEncoding: UTF-8

mittanareddy avatar Apr 20 '15 17:04 mittanareddy

have the same problem

tahsintahsin avatar Jul 03 '15 11:07 tahsintahsin

I am experiencing same problem. Any pointers would be helpful please

ehteshamy2k avatar Aug 12 '15 14:08 ehteshamy2k

Same issue also not able to provide a loop to generate unique Websocket connections anyone can help?

gauravmehta11 avatar Aug 13 '15 05:08 gauravmehta11

Same issue when I run a thread group with thread numbers larger than 1. Any existing solution to fix it?

peer2peer avatar Aug 20 '15 12:08 peer2peer

When I track in the code, I see that the session is null actually (session.getRemote().sendString(message); ) and before that, onOpen method wasn't called.

peer2peer avatar Aug 23 '15 07:08 peer2peer

Hello,

I amd using SignalR of Microsoft and I had the same issue: I digged into problem by using wireshark. I found out that Server was returning "http 500". On my side, Solution for this: Encode Token and ConnectionToken on jmeter.

Then next problem appeared: "Http 400" occured. I found another problem java.net.URI. The code in WebSocketSampler.java is like this: URI uri = new URI(protocol, null, domain, -1, path , queryString, null); ın this case querystring was encoded 2 times so the connectiontoken was encoded 2 times, therefore, Server can not understand connectiontoken so it returns HTTP 400. So I fixed the code like this: URI uri = new URI(protocol, null, domain, -1, path + "?" + queryString, null, null);

And Recompiled and installed with maven and put it in Jmeter. Now It is working on my side quite well.

I hope it will help.

Cheers,

ceritandogan avatar Aug 26 '15 12:08 ceritandogan

Hi,

I cannot find the source code in WebSocketSampler.java: URI uri = new URI(protocol, null, domain, -1, path , queryString, null);

Could you give more detailed info? Thanks.

peer2peer avatar Aug 27 '15 12:08 peer2peer

https://github.com/maciejzaleski/JMeter-WebSocketSampler/archive/version-1.0.2.zip src\main\java\JMeter\plugins\functional\samplers\websocket\WebSocketSampler.java Line 228 Line 230

ceritandogan avatar Aug 27 '15 18:08 ceritandogan

ceritandogan, Got it, thanks!

The problem is eased but not fixed completely yet. Could you give the code fix details? Thanks!

My problem is when I run a thread group with thread number of n (n > 1), all the thread will failed to connect to the server except the last one always succeed. Now with the fix, When n = 3, I got the last 2 threads succeed to connect to the server except the first one.

My fix done as ceritandogan gave:

        if (isProtocolDefaultPort()) {
//            return new URI(protocol, null, domain, -1, path, queryString, null);
        return new URI(protocol, null, domain, -1, path + "?" + queryString, null, null);
        }
//        return new URI(protocol, null, domain, Integer.parseInt(getServerPort()), path, queryString, null);
        return new URI(protocol, null, domain, Integer.parseInt(getServerPort()), path + "?" + queryString, null, null);

Also, I instrumented logs in WebSocket.java as below:

public void sendMessage(String message) throws IOException {
        if (session != null){
            logMessage.append(" - Session not null! JMeter.plugins.functional.samplers.websocket.ServiceSocket.sendMessage!").append("\n");
        } else {
            logMessage.append(" - Session null! JMeter.plugins.functional.samplers.websocket.ServiceSocket.sendMessage!").append("\n"); 
        }
        if (session.getRemote() != null)
            logMessage.append(" - session.getRemote not null! JMeter.plugins.functional.samplers.websocket.ServiceSocket.sendMessage!").append("\n");

        if (message != null)
            logMessage.append(" - ").append(message).append(" - mssage! JMeter.plugins.functional.samplers.websocket.ServiceSocket.sendMessage!").append("\n");

        session.getRemote().sendString(message);
    }

The failed thread's sampler results:

[Execution Flow]

  • Opening new connection
  • Using response message pattern ""
  • Using disconnect pattern ""
  • Waiting for the server connection for 5000 MILLISECONDS
  • Cannot connect to the remote server
  • Session null! JMeter.plugins.functional.samplers.websocket.ServiceSocket.sendMessage!

[Problems]

  • Unexpected error: null JMeter.plugins.functional.samplers.websocket.ServiceSocket.sendMessage(ServiceSocket.java:156) >JMeter.plugins.functional.samplers.websocket.WebSocketSampler.sample(WebSocketSampler.java:136) org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434) >org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261) java.lang.Thread.run(Unknown Source)

The code line numbers in the output are those of the origin source code before I changed any code.

The sampler results show that the session here is Null for the failed user. (- Session null! JMeter.plugins.functional.samplers.websocket.ServiceSocket.sendMessage!)

Any ideas?

peer2peer avatar Aug 30 '15 05:08 peer2peer

@peer2peer I updated jetty to use version 9.3.9.M1 and I am no longer getting this error.

conwilly88 avatar Apr 19 '16 14:04 conwilly88

@peer2peer ,I also have this problem,Could you tell me how to solve this problem or giving me your JMeterWebSocketSampler-1.0.2-SNAPSHOT.jar which you have modified.Thanks~~~~

Thread Name: Thread Group 1-1 Sample Start: 2015-04-20 13:18:38 EDT Load time: 5010 Connect Time: 0 Latency: 0 Size in bytes: 0 Headers size in bytes: 0 Body size in bytes: 0 Sample Count: 1 Error Count: 1 Response code: Response message:

[Execution Flow]

Opening new connection Using response message pattern "" Using disconnect pattern "" Waiting for the server connection for 5000 MILLISECONDS Cannot connect to the remote server [Variables]

Message count: 0 [Problems]

Unexpected error: null JMeter.plugins.functional.samplers.websocket.ServiceSocket.sendMessage(ServiceSocket.java:147) JMeter.plugins.functional.samplers.websocket.WebSocketSampler.sample(WebSocketSampler.java:116) org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434) org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261) java.lang.Thread.run(Unknown Source) Response headers:

SampleResult fields: ContentType: DataEncoding: UTF-8

x00350069 avatar Jul 07 '16 03:07 x00350069

@peer2peer, @conwilly88 & @x00350069 I have updated dependency to mentioned jar files, still facing the issue. Can you guys point me to right direction?

4M01 avatar Jun 14 '17 18:06 4M01

I also met this issue, @peer2peer, @conwilly88 & @x00350069 can you share a fixed jar file? Thanks.

luisxiaomai avatar Jul 14 '17 06:07 luisxiaomai