fabiolb / fabio

Consul Load-Balancing made simple
https://fabiolb.net
MIT License
7.26k stars 616 forks source link

Crash on route update: panic: runtime error: index out of range, diffmatchpatch.(*DiffMatchPatch).DiffCharsToLines #873

Closed ddreier closed 2 years ago

ddreier commented 2 years ago

After upgrading to 1.6.0 our Fabio instances with the largest number of routes (over 50k) started crashing with the following:

panic: runtime error: index out of range [65533] with length 55828
goroutine 75 [running]:
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).DiffCharsToLines(0xc0983f555302fcc9?, {0xc0174f4000, 0x87, 0xc03acf4000?}, {0xc017aca000, 0xda14, 0xc033cd1c2c?})
        /Users/njohnson/jetbrains/fabio/pkg/mod/github.com/sergi/go-diff@v1.1.0/diffmatchpatch/diff.go:452 +0x2bb
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).diffLineMode(0x466cae?, {0xc03194223c?, 0xc005f31c18?, 0x4b6c000?}, {0xc0364c423c, 0x11c257f, 0x120bf71}, {0xc0983f555302fcc9, 0x159d044387, 0x1310640})
        /Users/njohnson/jetbrains/fabio/pkg/mod/github.com/sergi/go-diff@v1.1.0/diffmatchpatch/diff.go:201 +0x15e
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).diffCompute(0x4b6c000?, {0xc03194223c?, 0x4b6c000?, 0xc036188000?}, {0xc0364c423c?, 0x40d539?, 0x120bf71}, 0x1, {0xc0983f555302fcc9, 0x159d044387, ...})
        /Users/njohnson/jetbrains/fabio/pkg/mod/github.com/sergi/go-diff@v1.1.0/diffmatchpatch/diff.go:188 +0x8c7
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).diffMainRunes(0x3b9aca00?, {0xc031606000?, 0x12dafc4?, 0xffffffffffffffff?}, {0xc036188000?, 0x4dac73?, 0x12dafc4?}, 0x0?, {0xc0983f555302fcc9, 0x159d044387, ...})
        /Users/njohnson/jetbrains/fabio/pkg/mod/github.com/sergi/go-diff@v1.1.0/diffmatchpatch/diff.go:119 +0x2bb
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).DiffMainRunes(0xc005f31de0?, {0xc031606000?, 0x12e073c?, 0x12e0800?}, {0xc036188000?, 0x12dafc4?, 0x12db000?}, 0x1?)
        /Users/njohnson/jetbrains/fabio/pkg/mod/github.com/sergi/go-diff@v1.1.0/diffmatchpatch/diff.go:95 +0xd9
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).DiffMain(...)
        /Users/njohnson/jetbrains/fabio/pkg/mod/github.com/sergi/go-diff@v1.1.0/diffmatchpatch/diff.go:85
main.logRoutes(0xc0003d9230?, {0xc01ccea000, 0x12e073c}, {0xc02d32a000, 0x12dafc4}, {0xcb8033?, 0xc00007f1a0?})
        /Users/njohnson/jetbrains/fabio/src/github.com/fabiolb/fabio/main.go:663 +0x19e
main.watchBackend(0xc0000d2a00, {0xc0003b17d0?, 0x6ef9a6?}, 0xc0000c2c60)
        /Users/njohnson/jetbrains/fabio/src/github.com/fabiolb/fabio/main.go:614 +0x477
created by main.main
        /Users/njohnson/jetbrains/fabio/src/github.com/fabiolb/fabio/main.go:140 +0x7f4

Ultimately it seems like the issue is probably in github.com/sergi/go-diff. But wanted to open this in case any one else runs into it.

ddreier commented 2 years ago

Looks like this might have been fixed in github.com/sergi/go-diff v1.2.0 based on sergi/go-diff#117.

nathanejohnson commented 2 years ago

Thank you for finding this! This will be incorporated with the next minor release, which should be very soon.

ddreier commented 2 years ago

Thanks! I tested and it looks like our issue is fixed.