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

bad request and disconnect immediately after connection established #812

Closed
sajjad-fatehi opened this issue May 12, 2024 · 6 comments
Closed

Comments

@sajjad-fatehi
Copy link

hi . in migration from v3 to v4.1.5:
when my client connects to centrifugo and authenticated without doing anything more my clients connection will close :
look at logs :

{"level":"debug","method":"POST","status":200,"path":"/centri/api","addr":"127.0.0.1:59932","duration":"208.345µs","time":"2024-05-12T09:09:11Z","message":"http request"}
{"level":"debug","client":"98cb7c5c-7915-4038-ade0-3a5fc9ecced8","user":"b80d637fac92eeb02cbdaf21","time":"2024-05-12T09:09:11Z","message":"client authenticated"}
{"level":"trace","client":"98cb7c5c-7915-4038-ade0-3a5fc9ecced8","reply":"{\"id\":1,\"connect\":{\"client\":\"98cb7c5c-7915-4038-ade0-3a5fc9ecced8\",\"version\":\"4.1.5\",\"data\":{\"sessionId\":\"b80d637fac92eeb02cbdaf21\",\"role\":\"Admin\",\"userId\":\"admin-f9a1ce063b22\",\"isPublic\":true,\"concurrent\":0,\"authId\":\"40\",\"connId\":\"98cb7c5c-7915-4038-ade0-3a5fc9ecced8\",\"roomId\":\"1-1-346\",\"ip\":\"10.10.10.10\"},\"ping\":25,\"pong\":true}}","user":"b80d637fac92eeb02cbdaf21","time":"2024-05-12T09:09:11Z","message":"-->"}
{"level":"info","client":"98cb7c5c-7915-4038-ade0-3a5fc9ecced8","error":"io: read/write on closed pipe","user":"b80d637fac92eeb02cbdaf21","time":"2024-05-12T09:09:11Z","message":"error reading command"}
{"level":"debug","client":"98cb7c5c-7915-4038-ade0-3a5fc9ecced8","duration":9.010011,"transport":"websocket","time":"2024-05-12T09:09:11Z","message":"client connection completed"}
{"level":"debug","client":"98cb7c5c-7915-4038-ade0-3a5fc9ecced8","reason":"bad request","user":"b80d637fac92eeb02cbdaf21","time":"2024-05-12T09:09:11Z","message":"closing client connection"}

image

and my client gets bad request error :
image

can you help how can i find issue of my logic ? i even read some of centrifugo source codes trying to find the same error message but didnt found

@FZambia
Copy link
Member

FZambia commented May 12, 2024

What is your full Centrifugo configuration?

@sajjad-fatehi
Copy link
Author

{
	"websocket_handler_prefix": "/messaging/connection/websocket",
	"sockjs_handler_prefix": "/messaging/connection/sockjs",
	"api_handler_prefix": "/centri/api",
	"admin_handler_prefix": "/centri",
	"proxy_connect_endpoint": "http://localhost:3100/api/monitor/connect",
	"proxy_connect_timeout": "15s",
	"engine": "redis",
	"redis_address": [
		"redis://localhost:6379"
	],
	"client_channel_limit": 4000,
	"admin": true,
	"port": 8000,
	"internal_port": 9000,
	"health": true,
	"debug": true,
	"grpc_api": true,
	"grpc_api_key": "xxx",
	"client_concurrency": 1,
	"token_hmac_secret_key": "xxx",
	"admin_password": "xxx",
	"admin_secret": "xxx",
	"api_key": "xxx",
	"publish": false,
	"prometheus": true,
	"presence": false,
	"join_leave": false,
	"history_size": 0,
	"log_level": "trace",
	"websocket_compression": true,
	"websocket_compression_level": 4,
	"client_insecure": true,
	"namespaces": [
		{
			"name": "system",
			"presence": true,
			"join_leave": true,
			"history_size": 10,
			"history_ttl": "120s",
			"allow_user_limited_channels": true,
			"allow_subscribe_for_client": true,
			"allow_subscribe_for_anonymous": false,
			"allow_publish_for_client": true,
			"allow_publish_for_anonymous": true,
			"allow_presence_for_subscriber": true,
			"allow_presence_for_anonymous": true,
			"allow_history_for_subscriber": true,
			"allow_history_for_anonymous": true,
			"force_recovery": true
		},
		{
			"name": "rooms",
			"presence": true,
			"join_leave": true,
			"history_size": 10,
			"history_ttl": "120s",
			"allow_user_limited_channels": true,
			"allow_subscribe_for_client": true,
			"allow_subscribe_for_anonymous": false,
			"allow_publish_for_client": true,
			"allow_publish_for_anonymous": true,
			"allow_presence_for_subscriber": true,
			"allow_presence_for_anonymous": true,
			"allow_history_for_subscriber": true,
			"allow_history_for_anonymous": true,
			"force_recovery": true
		},
		{
			"name": "usersession",
			"presence": true,
			"join_leave": true,
			"history_size": 10,
			"history_ttl": "120s",
			"allow_user_limited_channels": true,
			"allow_subscribe_for_client": true,
			"allow_subscribe_for_anonymous": false,
			"allow_publish_for_client": true,
			"allow_publish_for_anonymous": true,
			"allow_presence_for_subscriber": true,
			"allow_presence_for_anonymous": true,
			"allow_history_for_subscriber": true,
			"allow_history_for_anonymous": true,
			"force_recovery": true
		},
		{
			"name": "public",
			"presence": false,
			"join_leave": false,
			"history_size": 10,
			"history_ttl": "30s",
			"allow_user_limited_channels": true,
			"allow_subscribe_for_client": true,
			"allow_subscribe_for_anonymous": true,
			"allow_publish_for_client": true,
			"allow_publish_for_anonymous": true,
			"allow_history_for_subscriber": true,
			"allow_history_for_anonymous": true,
			"force_recovery": true
		}
	],
	"proxy_http_headers": [
		"Origin",
		"User-Agent",
		"Cookie",
		"Authorization",
		"X-Real-Ip",
		"X-Forwarded-For",
		"X-Request-Id"
	],
	"allowed_origins": [
		"*"
	],
	"history_ttl": "0s",
	"allow_anonymous_connect_without_token": true,
	"allow_user_limited_channels": true,
	"allow_subscribe_for_client": true,
	"allow_subscribe_for_anonymous": true,
	"allow_history_for_subscriber": true,
	"allow_history_for_anonymous": true,
	"force_push_join_leave": true
}

@FZambia
Copy link
Member

FZambia commented May 12, 2024

I guess Websocket compression was broken in Centrifugo at some point and recently fixed in https://github.com/centrifugal/centrifugo/releases/tag/v5.3.1 - there is exactly the error you've shown.

Current options for you:

  • do not use compression (i.e. make "websocket_compression" : false) - may result into more traffic
  • switch to Centrifugo v5

Can you do sth from the above?

@sajjad-fatehi
Copy link
Author

oops . after spending hours disabling it solved the problem.
thanks a lot .
actually at this moment ill do disable compression because i think migrate directly from v3 to v5 will cause more effort and problems (maybe) .
hmmm can we fix this v4 problem or it is not centrifugo's policy ?

@FZambia
Copy link
Member

FZambia commented May 13, 2024

Sorry, this fix won't land into v4, too much of maintenance overhead at this point. I suggest switching to v5 – the migration to it should be less radical than v3 -> v4.

@sajjad-fatehi
Copy link
Author

sajjad-fatehi commented May 13, 2024

I suggest switching to v5 – the migration to it should be less radical than v3 -> v4.

nice ! ill try.

i appreciate you.

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

2 participants