-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Hi, there are some mistakes, like the codes below, that will end up registering the same template to a session.
Lines 96 to 98 in 8c13bb0
| for _, tr := range tfs.Records { | |
| tr.register(s) | |
| } |
Lines 130 to 132 in 8c13bb0
| for _, record := range ofs.Records { | |
| record.register(s) | |
| } |
Lines 112 to 114 in 8c13bb0
| for _, record := range ots.Records { | |
| record.register(s) | |
| } |
Lines 100 to 102 in 8c13bb0
| for _, tr := range ts.Records { | |
| tr.register(s) | |
| } |
The problem is described below:
prior to Go 1.22, every freshly-declared loop variable used in a for loop is shared by all iterations during executing the loop.
I find this blog very helpful, please check!
I think there are two ways to fix the problem:
-
Add go.mod and declare go 1.22 or later. This will fix the problem without modifying any existing codes.
Here is the official Go blog for the problem fix: https://go.dev/blog/loopvar-preview -
Make a record copy in the loop and register the copy to session. This may be a better choice for backwards compatibility.
Thank you!