brocaar/chirpstack-simulator

[Bug] panic: invalid argument to Intn

JoseAmador95 opened this issue · 0 comments

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.

d, err := simulator.NewDevice(ctx, &wg,
simulator.WithDevEUI(devEUI),
simulator.WithAppKey(appKey),
simulator.WithUplinkInterval(s.uplinkInterval),
simulator.WithOTAADelay(time.Duration(mrand.Intn(int(s.activationTime)))),
simulator.WithUplinkPayload(false, s.fPort, s.payload),
simulator.WithGateways(gws),
simulator.WithUplinkTXInfo(gw.UplinkTXInfo{

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