brocaar / chirpstack-simulator

Simulator utility for the ChirpStack open-source LoRaWAN Network-Server.
https://www.chirpstack.io
MIT License
64 stars 52 forks source link

[Bug] panic: invalid argument to Intn #4

Closed JoseAmador95 closed 3 years ago

JoseAmador95 commented 3 years ago

Hi! I'm getting an error when running the simulator. It is related to the mrand.Intn function from math/rand in line 220 of simulator.go. According to the Go docs, the function panics when n < 0, but I couldn't get the instruction time.Duration(mrand.Intn(int(s.activationTime))) to output a negative value in order to replicate the issue, but hardcoding the whole instruction to a constant does make the simulator work as expected. The details of the error are shown below.

https://github.com/brocaar/chirpstack-simulator/blob/63fdb4934dbb52f363df97dcca4eaa333864d781/internal/simulator/simulator.go#L216-L223

Console Output panic: invalid argument to Intn

goroutine 57 [running]: math/rand.(Rand).Intn(0x1890160, 0xf8475800, 0x1a8e410) /usr/local/go/src/math/rand/rand.go:169 +0x7c math/rand.Intn(...) /usr/local/go/src/math/rand/rand.go:329 github.com/brocaar/chirpstack-simulator/internal/simulator.(simulation).runSimulation(0x1a46000, 0x0, 0x0) /home/pi/chirpstack-simulator/internal/simulator/simulator.go:220 +0x5a8 github.com/brocaar/chirpstack-simulator/internal/simulator.(*simulation).start(0x1a46000) /home/pi/chirpstack-simulator/internal/simulator/simulator.go:106 +0xb8 created by github.com/brocaar/chirpstack-simulator/internal/simulator.Start /home/pi/chirpstack-simulator/internal/simulator/simulator.go:69 +0x3a4