Giter Site home page Giter Site logo

go-pubsub's Introduction

Go Pub/Sub

An in-process simple publish/subscribe library for Golang .

API Reference

Why

I wrote this package so I can use it in my projects as a drop-in-replacement for redis pub/sub, actually this package was written for wsify v2

Contribution

I'm always open for any opinion

License

I'm using MIT license.

Known Users

go-pubsub's People

Contributors

alaaattya avatar alash3al avatar birkneralex avatar cornelk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-pubsub's Issues

Be great to have an example.go for Newbies

Hey just found your package and just trying to work it out. Be great for a simple example.go file that would be a bit help in understanding how to use this package quickly. :)

Memory Leak

There's a memory leak.

func (b *Broker) Attach ...
b.subscribers[s.id] = s

s is never removed from the b.subscribers, and the gc will not release the object.
BTW. Obviously b.subscribers is superfluous since it is not referenced anywhere.

regards Kay

Empty Topics

Currently when a topic becomes empty (all subscribers are unsubscribed), the topic is not removed from the topics map in the Broker struct.

Similarly, when a subscriber is detached from the broker it is:

  1. Marked as destroyed and channel is closed
  2. Unsubscribes from all topics, which goes back to my first case (empty topics aren't removed)

Why aren't empty topics being removed from the Broker?

Race condition

Ran into a race condition.
Seems to happen here: https://github.com/alash3al/go-pubsub/blob/master/broker.go#L88
Reference: https://tip.golang.org/doc/go1.8#mapiter

Is there a valid reason the Broadcast function got no mutex/lock?

fatal error: concurrent map iteration and map write
goroutine 127519 [running]:
runtime.throw(0xa481a5, 0x26)
/usr/lib/golang/src/runtime/panic.go:617 +0x72 fp=0xc000cc7838 sp=0xc000cc7808 pc=0x42f2b2
runtime.mapiternext(0xc000cc7920)
/usr/lib/golang/src/runtime/map.go:860 +0x597 fp=0xc000cc78c0 sp=0xc000cc7838 pc=0x410967
github.com/alash3al/go-pubsub.(*Broker).Broadcast(0xc000529d00, 0x9571e0, 0xc000c440b0, 0xc000c440c0, 0x1, 0x1)
/home/xxx/go/pkg/mod/github.com/alash3al/[email protected]/broker.go:88 +0x17d fp=0xc000cc7990 sp=0xc000>
ppp/cws/pkg/queue.PublishToWebsocketClose(...)
/home/xxx/yyy/zzz/go/src/ppp/cws/pkg/queue/pubsub,.go:38
ppp/cws/pkg/websocket.DockerConnection.func1(0xc000651080, 0xc0006da360, 0x24)
/home/xxx/yyy/zzz/go/src/ppp/cws/pkg/websocket/docker.go:52 +0x111 fp=0xc000cc79e8 sp=0xc000cc>
ppp/cws/pkg/websocket.DockerConnection(0xb45200, 0xc000289880, 0xc0001c4700)
/home/xxx/yyy/zzz/go/src/ppp/cws/pkg/websocket/docker.go:147 +0x83c fp=0xc000cc7bb8 sp=0xc000c>
net/http.HandlerFunc.ServeHTTP(...)
/usr/lib/golang/src/net/http/server.go:1995
ppp/cws/pkg/server.ValidateToken.func1(0xb45200, 0xc000289880, 0xc0001c4500)
/home/xxx/yyy/zzz/go/src/ppp/cws/pkg/server/auth.go:38 +0x293 fp=0xc000cc7c68 sp=0xc000cc7bb8 >
net/http.HandlerFunc.ServeHTTP(0xc00027a560, 0xb45200, 0xc000289880, 0xc0001c4500)
/usr/lib/golang/src/net/http/server.go:1995 +0x44 fp=0xc000cc7c90 sp=0xc000cc7c68 pc=0x72c654
net/http.(*ServeMux).ServeHTTP(0xf47d40, 0xb45200, 0xc000289880, 0xc0001c4500)
/usr/lib/golang/src/net/http/server.go:2375 +0x1d6 fp=0xc000cc7cf0 sp=0xc000cc7c90 pc=0x72e556
net/http.serverHandler.ServeHTTP(0xc000151380, 0xb45200, 0xc000289880, 0xc0001c4500)
/usr/lib/golang/src/net/http/server.go:2774 +0xa8 fp=0xc000cc7d20 sp=0xc000cc7cf0 pc=0x72f928
net/http.(*conn).serve(0xc0006a1400, 0xb46a00, 0xc0007767c0)
/usr/lib/golang/src/net/http/server.go:1878 +0x851 fp=0xc000cc7fc8 sp=0xc000cc7d20 pc=0x72b611
runtime.goexit()
/usr/lib/golang/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc000cc7fd0 sp=0xc000cc7fc8 pc=0x45e4e1
created by net/http.(*Server).Serve
/usr/lib/golang/src/net/http/server.go:2884 +0x2f4
goroutine 1 [IO wait, 1 minutes]:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.