-
Notifications
You must be signed in to change notification settings - Fork 34
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
Field index out of range while writing messages #66
Comments
Hello,are you using the library directly or through mavp2p? if you are using the library directly, which dialect are you using? |
I am using the library directly. Mavp2p is not involved. We're using a custom dialect that extends common and ardupilotmega along with some custom messages. |
Also, I've made sure that I'm using the dialect-import v2.0.4 to generate the go files along gomavlib v2.0.4 for the runtime. |
The crash you posted appears because the message you pass to WriteMessage is not the same of the one contained inside Dialect{}. |
Even I thought so and had tried to debug it from my side before posting it here. Before this I was using this version of gomavlib: github.com/aler9/gomavlib@v0.0.0-20220505052330-0c59caeb7516 After seeing the crash in 2.0.4, I shifted back to the version mentioned above, regenerated the old go files and everything was working fine. I've been using the above mentioned version for over a year now and it works stably. But I'll try to have a look at my custom messages again to see if I've made a mistake. |
The difficulty of debugging this issue also lays in a design flaw of the library: WriteMessageAll() can't return errors since writing is asynchronous, so the only way to report errors is to crash the library |
Anyway, the crash needs to be replicated before it can be solved. |
I am using the WriteFrameAll() function, I guess that has the same flaw.
I understand. I'll try to reproduce the problem and share the code. |
package main
import (
"fmt"
"log"
"math"
"time"
"github.com/bluenviron/gomavlib/v2"
"github.com/bluenviron/gomavlib/v2/pkg/dialects/common"
)
func main() {
nodeA := newNode(8120)
defer nodeA.Close()
nodeB := newNode(8220)
defer nodeB.Close()
nodeC := newNode(8320)
defer nodeC.Close()
go func() {
fmt.Println("nodeA: starting routing")
for event := range nodeA.Events() {
switch evt := event.(type) {
case *gomavlib.EventChannelOpen:
log.Println("nodeA: channel open")
case *gomavlib.EventChannelClose:
log.Println("nodeA: channel close")
case *gomavlib.EventParseError:
log.Println("nodeA: parse error")
case *gomavlib.EventFrame:
frame := evt.Frame
nodeB.WriteFrameAll(frame)
nodeC.WriteFrameAll(frame)
}
}
}()
go func() {
fmt.Println("nodeB: starting routing")
for event := range nodeB.Events() {
switch evt := event.(type) {
case *gomavlib.EventChannelOpen:
log.Println("nodeB: channel open")
case *gomavlib.EventChannelClose:
log.Println("nodeB: channel close")
case *gomavlib.EventParseError:
log.Println("nodeB: parse error")
case *gomavlib.EventFrame:
frame := evt.Frame
nodeA.WriteFrameAll(frame)
nodeC.WriteFrameAll(frame)
}
}
}()
go func() {
fmt.Println("nodeC: starting routing")
for event := range nodeC.Events() {
switch evt := event.(type) {
case *gomavlib.EventChannelOpen:
log.Println("nodeC: channel open")
case *gomavlib.EventChannelClose:
log.Println("nodeC: channel close")
case *gomavlib.EventParseError:
log.Println("nodeC: parse error")
case *gomavlib.EventFrame:
frame := evt.Frame
nodeA.WriteFrameAll(frame)
nodeB.WriteFrameAll(frame)
}
}
}()
for {
time.Sleep(time.Duration(math.MaxInt64))
}
}
func newNode(port uint32) *gomavlib.Node {
node, err := gomavlib.NewNode(gomavlib.NodeConf{
Endpoints: []gomavlib.EndpointConf{
gomavlib.EndpointTCPServer{Address: fmt.Sprintf("0.0.0.0:%d", port)},
},
Dialect: common.Dialect,
OutVersion: gomavlib.V2,
OutSystemID: 2,
OutComponentID: 5,
HeartbeatDisable: true,
})
if err != nil {
log.Panicf("cannot create mavlink node: %s", err)
}
return node
} |
I noticed that the crash does not occur when there were only 2 nodes. It started occurring when I created 3 nodes. In my application I have multiple such nodes. If you have mavlink-router and some SITL instance installed on your system, then you can use these commands to connect to the application:
|
The logs:
|
I'm sorry, I made a small mistake in the code I had posted earlier. I have updated the comment. |
The reason why the crash happens is that passing the same |
Oh, that makes sense. I guess because the writing is happening in different coroutines, wrapping the WriteFrameAll() in a mutex lock won't fix it. Can you please suggest a way in which I can send the frames to multiple nodes?? |
this is fixed in v2.1.0. |
Thanks a lot @aler9 for fixing this! |
This issue is being locked automatically because it has been closed for more than 6 months. |
I have an application that needs to route messages between a few endpoints based on some criteria. When I was using older versions of gomavlib it used to work great. But after updating recently, I have started seeing crashes. The routing works fine for some time but the crash occurs randomly in a few seconds.
I have added the crash logs:
The text was updated successfully, but these errors were encountered: