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

Events emitted from server not heard by client #52

Closed
mwilc0x opened this issue Dec 14, 2014 · 12 comments
Closed

Events emitted from server not heard by client #52

mwilc0x opened this issue Dec 14, 2014 · 12 comments

Comments

@mwilc0x
Copy link

mwilc0x commented Dec 14, 2014

Hi, first thank you for this project.

I am working on simple demo to stream some data to the client. I am running into an issue where I am not hearing events which are emitted from server on the client. Here is what my use case looks like:

Server:

server.On("connection", func(so socketio.Socket) {
   log.Println("user connected")

   go tweets()

   so.On("get-tweets-data", func() {
       log.Println("I heard event from client!")
       so.Emit("tweets-data")
   })
   so.On("disconnection", func() {
       log.Println("user disconnected")
   })
})

Client:

socket.on('connect', function(data) {

  socket.emit('get-tweets-data');

  socket.on('tweets-data', function(data) {
    console.log('received data from the server');
  });

});

I heard the initial "get-tweets-data" call from the client, but after that when I try to callback to the client from server something gets lost in translation.

If I move the Emit outside of the On event, it works fine.

server.On("connection", func(so socketio.Socket) {
   log.Println("user connected")

   go tweets()

   so.On("get-tweets-data", func() {
       log.Println("I heard event from client!")
   })
   so.On("disconnection", func() {
       log.Println("user disconnected")
   })
   so.Emit("tweets-data")
})
@mountkin
Copy link
Contributor

Hi, @mjw56
Please try the patch I posted at #53 and see if it works.
By the way, can you print out the return value of so.Emit call and see if it's something like "upgrading"?

@mwilc0x
Copy link
Author

mwilc0x commented Dec 20, 2014

Hey @mountkin, I made the change as you had suggested.

I'm seeing that the use case I described above is now working. I'm also seeing that when I print out return value for so.Emit I do see "upgrading" still.

@mountkin
Copy link
Contributor

@mjw56 did you remove the precompiled archives under $GOPATH/pkg/xxx/github.com/googollee/ directory after you apply the patch?

Edit:
I misunderstood your last comment and thought it's still not working. Now if it works please ignore this comment.

@mwilc0x
Copy link
Author

mwilc0x commented Dec 20, 2014

@mountkin No worries, it is working now :)

Thank you for your help. Any chance this can make it into master so others don't face this problem?

@googollee
Copy link
Owner

As I merged the go-engine.io, please check this issue again. Thanks.

@mattmassicotte
Copy link

I know its been a while since this issue has been touched, but as of master on April 15th, 2015, I'm experiencing a similar issue. It appears that Emits that occur in the On("connection",..) function work, but all other emits return the "upgrading" error.

@alecthomas
Copy link

I'm having the same issue, though not reliably. Sometimes it errors with "upgrading", sometimes it doesn't.

@syhlion
Copy link

syhlion commented Jul 21, 2015

I'm having the same issue +1

@moul
Copy link

moul commented Jun 26, 2016

Same problem here 👍

@bieleckim
Copy link

+1

@pgamaster
Copy link

+1 upgrading error under 2000+ clients

@erkie
Copy link
Collaborator

erkie commented Feb 8, 2019

Closing this issue because it is old. There are a couple of newer issues with the same problem so please refer to those. Thanks!

@erkie erkie closed this as completed Feb 8, 2019
hoo-ge added a commit to hoo-ge/go-socket.io that referenced this issue Sep 18, 2020
* protect sessions map

* hide onOpen from server

* extract newId()

* use rwmutex in sessions

* hide transport implement

* sync transport method

* update readme

* clear document

* add unit test of transport and server

* add unit test for sessions, add race test

* change the way to config server, remove DefaultConfig

* add set function test

* update example in readme

* fix race test

* update document

* update readme

* fix typo

* fix xhr-polling response header problem.

* function payloadEncoder.IsString()

* connection info

* remove transport when conn closed

* serveHttp closed conn

* fix race test

* server won't send ping, fix websocket double close

* use rwmutex in websocket

* fix websocket connect directly, googollee#5

* fix issue googollee#6, won't close readerChan when conn is closed, bypass _OPEN packet when onPacket

* refactor websocket

* back the old code

* fix polling

* add polling server

* add test

* update websocket client

* fix test

* add polling client

* update conn

* fix build

* remove file

* add serve http

* new conn check name

* Close readerChan on disconnect.

* Return initialized empty array.

* add conn test

* fix race issue

* fix upgrade test

* fix closing

* fix race

* add server

* send open event

* fix unit test

* upgrades return [] instead of nil

* update goconvey

* add server test

* remove files

* Add JSONP Polling support

* wait and retry if the server state is "upgrading" when calling NextWriter.
This is a fix to googollee#52

* fix panic, issue googollee#14

* roll back

* added feature to set max connection

* added feature to allow custom connection id generator

* fix missing vars

* fix missing return

* Fix typo

* custom sessions

* rename

* rename

* bugfix - the conn can be nil

* clean up upgrading ws connection fd

* Close websocket when NextReader returns error

According to the docs of gorilla/websocket, one should
close the connection if the reader fails.

* Fix set cookie

Previous behaviour would reset all cookies visible in the current scope
with possibly wrong values.

Fixes googollee#24

* Make the server decrement the connection count when it returns 503 "too many connections"

On every open request, the server increments its current connection count, but it does not correctly decrement it when a connection errors out because of too many connections.

* added Count() and GetMaxConnections() to view connected count in session

* removed Count() from sessions interface and using server.currentConnection

* Multiple goroutine send message to client with lock

* Multiple goroutine send message to client with lock

* server_conn_test.go bug修改,会导致conn为nil,导致panic

* update go version in ci

* fix test

* fix test

* Wait for close in tests that need to check it.

This fixes a data race warning and a test that sometimes fails.

* rewrite payload & packet

* update ci

* add coverall

* fix coverall

* add coverage badge

* update ci

* finish websocket transport

* add manager test

* update transport

* update transport

* update payload

* update payload

* add doc

* add set deadline

* rename

* add timeout error

* update model for polling

* add polling transport

* add string test

* payload add atomic error to save differen type error

* update transport/polling

* add jsonp

* fix mime

* add jsonp test

* add set deadline tests

* check timeout error

* update transport

* update transport interface

* add engineio code

* server finish

* remove node

* update gitignore

* update demo

* add pause resume

* fix race unit test

* fix uprading

* add upgrade workflow

* refactor payload, supported waiting other goroutine while pausing

* add pause/resume to payload, change reader to readcloser

* refactor upgradable client

* update ci env

* update checker

* update ci env

* fix doc

* fix upgrade

* add dial query

* fix demo client.go

* remove retry in polling, should use http.Transport.DialContext to retry

* fix unit test

* remove xtest

* update demo/client

* rename

* -> net.Addr

* add unit test

* support gopkg.in

* update ut

* add session id generator

* update go to 1.7.2

* fix upgrade racing; add web demo

* move js & html to asset

* add Server.Close()

* fix: old transport request hang when doing upgrading

* resume old transport if upgrading failed

* Config -> Options, add Options.ConnInitor to init Conn with httpRequest

* add pauser for payload.Decoder

* Fix pausing block when multi-pausing at same time

* add pausing trigger and paused trigger, for payload

* fix pause

* update go version in ci

* when upgrade error, the nums of the connection wont'b release

* Add mutex for ping to prevent 'send on closed channel' race condition

* Add extra lock

* fix conn count bug

使用了这个库,一晚上过来发现所有请求都503了,错误是too many connections,但是查看tcp连接却很少,
查下来是没有在创建conn失败的时候减小统计值,提交该修复如上

* Fixed concurrent writing and closing for writer struct (and reading/closing for reader)

* Fixed concurrent writing and closing for writer struct (and reading/closing for reader) + fixed deadlock

* Set state of closing before closing the socket. Should fix a couple of panics for related code

* Implement CheckOrigin pass-through to the gorilla Upgrader, otherwise
there was no way of handling Origin checking.

* safety check for double upgrade

* lock in the right place

* dont debug on bypassing the issue

* add module support

* add go module support

* test with latest go version.

* remove gopkg.in, use go module version

* fix travis

* fix travis ci

* fix: Response and ack from server are slow googollee#238

add a write locker, so that write don't need to wait for read
to time out

Signed-off-by: Wang Yufei <wangyufei@dobest.com>

* fix: concurrent write to websocket connection panic googollee#74

as https://godoc.org/github.com/gorilla/websocket#hdr-Concurrency said,
Connections support one concurrent reader and one concurrent writer.
Applications are responsible for ensuring that no more than one goroutine calls the write methods (NextWriter, SetWriteDeadline, WriteMessage, WriteJSON, EnableWriteCompression, SetCompressionLevel) concurrently and that no more than one goroutine calls the read methods (NextReader, SetReadDeadline, ReadMessage, ReadJSON, SetPongHandler, SetPingHandler) concurrently.

Signed-off-by: Wang Yufei <wangyufei@dobest.com>

* fix concurrent write to ws.conn

* session: upgradeLocker is for protecting the session.conn field,
not concurrent writes on the actual connection.

Remove lockers from session since they are in the wrapper.

util: use full write lock, not read lock, with reader.Close and reader.Read

With RLock and RUnlock, concurrent reads were not prevented, but this
is a requirement of gorilla's connection read methods too.

Change the locker type in both reader and writer from *sync.RWMutex
to sync.Locker, which is satisfied by both Mutex and RWMutex.
No longer use newWriter and newReader from util.go since the locking is
in the wrapper.
Note: util.go is now UNUSED.

transport/websocket: wrapper needs locking around reads too

Add wrapper.readLocker, and use it in NextReader.
Add rcWrapper, similar to wcWrapper, for unlocking the wrapper's read
lock on Close.

packet: a failed read from a decoder must close the reader

As in (*encoder).NextWriter, which calls the writer's Close method when
a Write fails, (*decoder).NextReader must call the reader's Close method
on a failed read (io.ReadFull).

go.mod needs a go version line since Go 1.13 adds one

* close in the right place

* TestWebsocket needs to Close the readers too

* session: during upgrade, close reader after echo in reply

* typo

* more meticulous closing of FrameReaders and FrameWriters in (*session).upgrading

* ignore Copy error in wrapper's FrameReader Close

* remove unused Server.locker

* make a nagger in case Close isn't called

nagger for the writer too

* transport/websocket: wrapper.NewReader must unlock if invalid message type is read

* transport/polling, demos: must close writers and readers on early return cases

more diligent closing in example and packet tests

* change client timeout to pingInterval+pingTimeout

* fix: don't call http.Error a second time, if it was already called internally by websocket library.

* chore: add ignore idea directory

* fix: change order of variables to ensure correct 64bit alignment on ARM processors

* fix: just use int32 as we only store 0 and 1 instead of having to force arrangement on struct

* feat(polling): handle OPTIONS requests and set headers like in standard engine.io implementation

* fix(polling): don't check origin by default to keep the old behaviour

* refactor(polling): remove mergo dependency, run go mod tidy and suggest other way of handling defaults

* Add example for echo framework

* Set context of the engineio.Conn to socketio.Conn

* rename _example/echo to _example/go-exho

* Fix typo

* Fix googollee#347: check if Namespace field has a '?' and if so, slice it to another field Query

* fix bug, can't close read/write io correctly.

* ADD: new example with gf web framework

* Update imports, remove old files, fix go.mod

* Update README with breaking change notice

* Add engineio section to README

* Add method for counting connected clients

* Remove [BUG] prefix from bug issue template

Co-authored-by: Googol Lee <i@googol.im>
Co-authored-by: toritori0318 <toritori0318@gmail.com>
Co-authored-by: Mattias Granlund <mtsgrd@gmail.com>
Co-authored-by: Chi Vinh Le <cvl@chinet.info>
Co-authored-by: mountkin <mountkin@gmail.com>
Co-authored-by: Masaki Fujimoto <masaki.fujimoto@gree.net>
Co-authored-by: Ruben Vermeersch <ruben@rocketeer.be>
Co-authored-by: Konstantinos Aravanis <konstantinos.aravanis@centralway.com>
Co-authored-by: artushin <artushin@gmail.com>
Co-authored-by: Michael Weibel <michael.weibel@gmail.com>
Co-authored-by: Matthew Conger-Eldeen <mceldeen@gmail.com>
Co-authored-by: Tyler Pham <tpham@pesa.com>
Co-authored-by: DisruptiveMind <tyler@disruptiveart.com>
Co-authored-by: shouhui.he <shouhui.he@gensee-inc.com>
Co-authored-by: zhouhui8915 <zhouhui8915@google.com>
Co-authored-by: Nikola Kovacs <nikola.kovacs@gmail.com>
Co-authored-by: zhangsong <zhangsong@taqu.cn>
Co-authored-by: Timothy Studd <tim@timstudd.com>
Co-authored-by: liqi7417 <2273172321@qq.com>
Co-authored-by: Eugene Yudkin <yudkin.e@i20.biz>
Co-authored-by: Erik Rothoff Andersson <erik.rothoff@gmail.com>
Co-authored-by: Alexandre Bourget <alex@bourget.cc>
Co-authored-by: steveoc <steveoc64@gmail.com>
Co-authored-by: Wang Yufei <wangyufei@dobest.com>
Co-authored-by: wangtuanjie <wangtuanjie@bytedance.com>
Co-authored-by: Jonathan Chappelow <chappjc@protonmail.com>
Co-authored-by: criyle <gaoyang4425@gmail.com>
Co-authored-by: Adrian <git@adrianmxb.com>
Co-authored-by: Shaplygin Semen <shaplygin-sa@ozon.ru>
Co-authored-by: annlumia <ann.lumia@live.com>
Co-authored-by: tomruk <41700170+tomruk@users.noreply.github.com>
Co-authored-by: Adrian B <adrianmxb@adrianmxb.com>
Co-authored-by: Ade Viankakrisna Fadlil <viankakrisna@gmail.com>
Co-authored-by: Saimon Shaplygin <semyuon@gmail.com>
Co-authored-by: Denis Borzenko <d.borzenko@hpmd.ru>
Co-authored-by: clearcode <34591322+clearcodecn@users.noreply.github.com>
Co-authored-by: jangworn <jangworn@163.com>
Watcher919 pushed a commit to Watcher919/Go-socket that referenced this issue Sep 1, 2024
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

10 participants