Code Monkey home page Code Monkey logo

arigo's People

Contributors

dependabot[bot] avatar fooofei avatar idileepd avatar jae-jae avatar jinxuyang avatar rgl avatar siku2 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

Watchers

 avatar  avatar  avatar

arigo's Issues

panic: read websocket after it was closed

I write a example like that:

package main

import (
	aria2 "github.com/siku2/arigo"
)

func Get() error {
	url := "ws://127.0.0.1:6800/jsonrpc"
	conn, err := aria2.Dial(url, "")
	if err != nil {
		return err
	}
	defer conn.Close()

	if _, err := conn.TellActive("gid"); err != nil {
		return err
	}

	return nil
}

func main() {
	for {
		if err := Get(); err != nil {
			panic(err)
		}
	}
}

And got panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xc0 pc=0x63757d]

goroutine 34 [running]:
github.com/gorilla/websocket.(*Conn).NextReader(0x0)
        /root/go/pkg/mod/github.com/gorilla/[email protected]/conn.go:1000 +0x1d
github.com/siku2/arigo/internal/pkg/wsrpc.(*ReadWriteCloser).Read(0xc0002061b0, {0xc0001a0200, 0x200, 0x200})
        /root/go/pkg/mod/github.com/siku2/[email protected]/internal/pkg/wsrpc/rwc.go:26 +0x45
encoding/json.(*Decoder).refill(0xc00022e000)
        /usr/local/go/src/encoding/json/stream.go:165 +0x188
encoding/json.(*Decoder).readValue(0xc00022e000)
        /usr/local/go/src/encoding/json/stream.go:140 +0xbb
encoding/json.(*Decoder).Decode(0xc00022e000, {0x652b20, 0xc000230020})
        /usr/local/go/src/encoding/json/stream.go:63 +0x78
github.com/cenkalti/rpc2/jsonrpc.(*jsonCodec).ReadHeader(0xc000230000, 0xc0000121c8, 0xc0000121e0)
        /root/go/pkg/mod/github.com/cenkalti/[email protected]/jsonrpc/jsonrpc.go:93 +0x85
github.com/cenkalti/rpc2.(*Client).readLoop(0xc000216070)
        /root/go/pkg/mod/github.com/cenkalti/[email protected]/client.go:87 +0x12d
github.com/cenkalti/rpc2.(*Client).Run(...)
        /root/go/pkg/mod/github.com/cenkalti/[email protected]/client.go:62
github.com/siku2/arigo.(*Client).Run(0x0?)
        /root/go/pkg/mod/github.com/siku2/[email protected]/client.go:97 +0x1c
created by github.com/siku2/arigo.DialContext
        /root/go/pkg/mod/github.com/siku2/[email protected]/client.go:82 +0x40a
exit status 2

Maybe we shoule use a Mutex to protect the websocket from reading after it was closed?

getting GID

is it possible to get GID just after adding the url instead of getting it after complete download?

Wrong Subscribe() logic

When first time call Client.Subscribe, it registers two function, the first one is nil, which causes crash when this event triggers.

The logic from source:

func (c *Client) Subscribe(name string, listener EventListener) {
	listeners, ok := c.listeners[name]
	if !ok {
		listeners = make([]EventListener, 1)
		c.listeners[name] = listeners
	}

	c.listeners[name] = append(listeners, listener)
}

Should be:

func (c *Client) Subscribe(name string, listener EventListener) {
	listeners, ok := c.listeners[name]
	if !ok {
		c.listeners[name] = []EventListener{listener}
	} else {
		c.listeners[name] = append(listeners, listener)
	}
}

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.