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

panic: runtime error: slice bounds out of range #2

Open
florianjs opened this issue Apr 13, 2020 · 2 comments
Open

panic: runtime error: slice bounds out of range #2

florianjs opened this issue Apr 13, 2020 · 2 comments

Comments

@florianjs
Copy link

florianjs commented Apr 13, 2020

Hi :)
I have an issue when I try to send a message from a server (Terminal 1) to more than one client (Terminal 2 and 3)

Problem Description:

panic: runtime error: slice bounds out of range [:535024639] with capacity 359

goroutine 36 [running]:
github.com/v-braun/go2p.middlewareHeadersImpl(0xc00040c000, 0xc00040c0a0, 0xc000050080, 0x1, 0x1, 0x0)
        C:/Users/argau/go/src/github.com/v-braun/go2p/middleware_headers.go:57 +0x45b
github.com/v-braun/go2p.(*Pipe).process(0xc00040c0a0, 0xc000050080, 0x4, 0x4)   
        C:/Users/argau/go/src/github.com/v-braun/go2p/pipe.go:63 +0x3b0
github.com/v-braun/go2p.(*Peer).processPipe(0xc00040c000, 0xc000050080, 0x1)    
        C:/Users/argau/go/src/github.com/v-braun/go2p/peer.go:71 +0x93
github.com/v-braun/go2p.(*Peer).start.func3()
        C:/Users/argau/go/src/github.com/v-braun/go2p/peer.go:48 +0x1a7
github.com/v-braun/awaiter.(*awaiter).Go.func1(0xc00040e0e0, 0xc00040e020)      
        C:/Users/argau/go/src/github.com/v-braun/awaiter/awaiter.go:51 +0x59    
created by github.com/v-braun/awaiter.(*awaiter).Go
        C:/Users/argau/go/src/github.com/v-braun/awaiter/awaiter.go:49 +0x6a    
exit status 2
package main

import (
	"bufio"
	"flag"
	"fmt"
	"os"
	"strings"

	"github.com/fatih/color"
	"github.com/sirupsen/logrus"
	"github.com/v-braun/go2p"
	prefixed "github.com/x-cray/logrus-prefixed-formatter"
)

func main() {
	logrus.SetFormatter(new(prefixed.TextFormatter))
	logrus.SetOutput(os.Stdout)
	logrus.SetLevel(logrus.DebugLevel)

	/* 	localHost := "localhost:7071"
	 */
	localAddr := flag.String("laddr", "localhost:7071", "local ip address")
	flag.Parse()

	cyan := color.New(color.FgCyan).SprintFunc()
	blue := color.New(color.FgHiBlue).SprintFunc()
	green := color.New(color.FgHiGreen).SprintFunc()
	white := color.New(color.FgHiWhite).SprintFunc()
	peerName := color.New(color.BgBlue, color.FgHiWhite).SprintFunc()

	/* 	if localHost == "localhost:7071" {
	   		peerName = color.New(color.BgHiMagenta, color.FgHiWhite).SprintFunc()
	   	} else if localHost == "localhost:7072" {
	   		peerName = color.New(color.BgHiYellow, color.FgHiWhite).SprintFunc()
	   	} */

	net := go2p.NewNetworkConnectionTCP(*localAddr, &map[string]func(peer *go2p.Peer, msg *go2p.Message){
		"msg": func(peer *go2p.Peer, msg *go2p.Message) {
			fmt.Println(fmt.Sprintf("%s %s", peerName(peer.RemoteAddress()+" > "), msg.PayloadGetString()))
		},
	})

	err := net.Start()
	if err != nil {
		panic(err)
	}

	net.OnPeer(func(p *go2p.Peer) {
		fmt.Printf("%s %s\n", cyan("new peer:"), green(p.RemoteAddress()))
	})

	defer net.Stop()

	fmt.Println(cyan(`
local server started!
press:
	`))

	fmt.Printf("%s %s\n", blue("[q][ENTER]"), white("to exit"))
	fmt.Printf("%s %s\n", blue("[c {ip address : port}][ENTER]"), white("to connect to another peer"))
	fmt.Printf("%s %s\n", blue("[any message][ENTER]"), white("to send a message to all peers"))

	reader := bufio.NewReader(os.Stdin)
	for {
		text, _ := reader.ReadString('\n')
		text = strings.TrimSpace(text)
		if text == "q" {
			return
		} else if strings.HasPrefix(text, "c ") {
			text = strings.TrimPrefix(text, "c ")
			net.ConnectTo("tcp", text)
		} else {
			net.SendBroadcast(go2p.NewMessageRoutedFromString("msg", text))
		}
	}
}

First Terminal
go run main.go
Second Terminal
go run main.go -laddr=localhost:7072
c localhost:7071
Third Terminal
go run main.go -laddr=localhost:7073
c localhost:7071

First Terminal
Send A Message

Second or Third Terminal will panic

Environment:

  • Windows 10
  • Latest Verison of Go2p
@florianjs
Copy link
Author

florianjs commented Apr 13, 2020

Server :

[0017] DEBUG middleware_log: tcp:127.0.0.1:59529 out-
> (358 bytes) - local endpoint: tcp:127.0.0.1:7071

Client :

[0016] DEBUG pipe: execute middleware msg-len
m=300 name=log op=Receive pos=3
[0016] DEBUG middleware_log: tcp:127.0.0.1:7071 <--in
 (300 bytes) - local endpoint: tcp:127.0.0.1:59224
[0016] DEBUG pipe: execute middleware msg-len
m=300 name=Crypt op=Receive pos=2
[0016] DEBUG pipe: execute middleware msg-len
m=643 name=log op=Receive pos=3
[0016] DEBUG middleware_log: tcp:127.0.0.1:7071 <--in
 (643 bytes) - local endpoint: tcp:127.0.0.1:59224
[0016] DEBUG pipe: execute middleware msg-len
m=643 name=Crypt op=Receive pos=2
[0016] DEBUG pipe: execute middleware msg-len
m=359 name=headers op=Receive pos=1
panic: runtime error: slice bounds out of range [:2133614430] with capacity 358

I don't know where this [:2133614430] came from?

header := full[8 : 8+headerSize] 

line 57 middleware_headers I guess ?

@v-braun
Copy link
Owner

v-braun commented Sep 21, 2020

Very detailed information and logs! Thanks a lot I will check this issue asap.

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