Skip to content
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

Race condition on version 1.0.7 #18

Open
mamazinho opened this issue Jun 23, 2023 · 3 comments
Open

Race condition on version 1.0.7 #18

mamazinho opened this issue Jun 23, 2023 · 3 comments

Comments

@mamazinho
Copy link

In version 1.0.6 we were able to mock time.Now easily.
Changing to 1.0.7, tests who contains this use start to break:

	patch, _ := mpatch.PatchMethod(
		time.Now, func() time.Time {
			loc, _ := time.LoadLocation("America/Sao_Paulo")
			return time.Date(2000, 12, 15, 17, 8, 00, 0, loc)
		})
	defer patch.Unpatch()

This code is given me the following stack error:

Running tool: /usr/local/go/bin/go test -timeout 30s -run ^TestAdapter_GetOlistOrder$ gitlab.olist.io/channels/integrations/channels-integrations/internal/pkg/channels/via/orders/outbound

fatal: morestack on g0
SIGTRAP: trace trap
PC=0x4fe9a2 m=0 sigcode=128

goroutine 0 [idle]:
runtime.abort()
/usr/local/go/src/runtime/asm_amd64.s:1059 +0x2 fp=0x7ffd111ad4f8 sp=0x7ffd111ad4f0 pc=0x4fe9a2
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:538 +0x25 fp=0x7ffd111ad500 sp=0x7ffd111ad4f8 pc=0x4fca05

goroutine 1 [chan receive]:
runtime.gopark(0x20915a0?, 0xc00033faa8?, 0x5f?, 0xde?, 0x7f8e3bbc0108?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc00033fa28 sp=0xc00033fa08 pc=0x4cd336
runtime.chanrecv(0xc00004c150, 0xc00033fb27, 0x1)
/usr/local/go/src/runtime/chan.go:583 +0x49b fp=0xc00033fab8 sp=0xc00033fa28 pc=0x4971fb
runtime.chanrecv1(0xc000709230?, 0x1?)
/usr/local/go/src/runtime/chan.go:442 +0x18 fp=0xc00033fae0 sp=0xc00033fab8 pc=0x496cf8
testing.(*T).Run(0xc000103ba0, {0x143f1de?, 0x5afb65?}, 0x148e748)
/usr/local/go/src/testing/testing.go:1494 +0x37a fp=0xc00033fb80 sp=0xc00033fae0 pc=0x5b0f7a
testing.runTests.func1(0xc000103ba0?)
/usr/local/go/src/testing/testing.go:1846 +0x6e fp=0xc00033fbd0 sp=0xc00033fb80 pc=0x5b2ece
testing.tRunner(0xc000103ba0, 0xc00033fcd8)
/usr/local/go/src/testing/testing.go:1446 +0x10b fp=0xc00033fc20 sp=0xc00033fbd0 pc=0x5b018b
testing.runTests(0xc00070caa0?, {0x1fce620, 0x8, 0x8}, {0x7f8e3bbc0108?, 0x40?, 0x2056d00?})
/usr/local/go/src/testing/testing.go:1844 +0x456 fp=0xc00033fd08 sp=0xc00033fc20 pc=0x5b2d76
testing.(*M).Run(0xc00070caa0)
/usr/local/go/src/testing/testing.go:1726 +0x5d9 fp=0xc00033ff00 sp=0xc00033fd08 pc=0x5b1859
main.main()
_testmain.go:63 +0x1aa fp=0xc00033ff80 sp=0xc00033ff00 pc=0xda43ea
runtime.main()
/usr/local/go/src/runtime/proc.go:250 +0x212 fp=0xc00033ffe0 sp=0xc00033ff80 pc=0x4ccf72
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00033ffe8 sp=0xc00033ffe0 pc=0x4feb41

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000074fb0 sp=0xc000074f90 pc=0x4cd336
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:369
runtime.forcegchelper()
/usr/local/go/src/runtime/proc.go:302 +0xad fp=0xc000074fe0 sp=0xc000074fb0 pc=0x4cd1cd
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000074fe8 sp=0xc000074fe0 pc=0x4feb41
created by runtime.init.6
/usr/local/go/src/runtime/proc.go:290 +0x25

goroutine 3 [GC sweep wait]:
runtime.gopark(0x1?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000075790 sp=0xc000075770 pc=0x4cd336
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:369
runtime.bgsweep(0x0?)
/usr/local/go/src/runtime/mgcsweep.go:297 +0xd7 fp=0xc0000757c8 sp=0xc000075790 pc=0x4b76d7
runtime.gcenable.func1()
/usr/local/go/src/runtime/mgc.go:178 +0x26 fp=0xc0000757e0 sp=0xc0000757c8 pc=0x4ac346
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000757e8 sp=0xc0000757e0 pc=0x4feb41
created by runtime.gcenable
/usr/local/go/src/runtime/mgc.go:178 +0x6b

goroutine 4 [runnable]:
runtime.gopark(0xc00004c0e0?, 0x17dc488?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000075f70 sp=0xc000075f50 pc=0x4cd336
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:369
runtime.(*scavengerState).park(0x2056e20)
/usr/local/go/src/runtime/mgcscavenge.go:389 +0x53 fp=0xc000075fa0 sp=0xc000075f70 pc=0x4b5733
runtime.bgscavenge(0x0?)
/usr/local/go/src/runtime/mgcscavenge.go:622 +0x65 fp=0xc000075fc8 sp=0xc000075fa0 pc=0x4b5d25
runtime.gcenable.func2()
/usr/local/go/src/runtime/mgc.go:179 +0x26 fp=0xc000075fe0 sp=0xc000075fc8 pc=0x4ac2e6
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000075fe8 sp=0xc000075fe0 pc=0x4feb41
created by runtime.gcenable
/usr/local/go/src/runtime/mgc.go:179 +0xaa

goroutine 5 [finalizer wait]:
runtime.gopark(0x2057900?, 0xc000007860?, 0x0?, 0x0?, 0xc000074770?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000074628 sp=0xc000074608 pc=0x4cd336
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:369
runtime.runfinq()
/usr/local/go/src/runtime/mfinal.go:180 +0x10f fp=0xc0000747e0 sp=0xc000074628 pc=0x4ab44f
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000747e8 sp=0xc0000747e0 pc=0x4feb41
created by runtime.createfing
/usr/local/go/src/runtime/mfinal.go:157 +0x45

goroutine 7 [GC worker (idle)]:
runtime.gopark(0xc000076780?, 0x495f9d?, 0x15?, 0x0?, 0xc0000767a8?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000076750 sp=0xc000076730 pc=0x4cd336
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0000767e0 sp=0xc000076750 pc=0x4ae491
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000767e8 sp=0xc0000767e0 pc=0x4feb41
created by runtime.gcBgMarkStartWorkers
/usr/local/go/src/runtime/mgc.go:1159 +0x25

goroutine 19 [GC worker (idle)]:
runtime.gopark(0x176360c285633?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000070750 sp=0xc000070730 pc=0x4cd336
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0000707e0 sp=0xc000070750 pc=0x4ae491
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000707e8 sp=0xc0000707e0 pc=0x4feb41
created by runtime.gcBgMarkStartWorkers
/usr/local/go/src/runtime/mgc.go:1159 +0x25

goroutine 20 [GC worker (idle)]:
runtime.gopark(0x176360c28b48b?, 0x3?, 0x8d?, 0x3a?, 0x0?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000070f50 sp=0xc000070f30 pc=0x4cd336
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1235 +0xf1 fp=0xc000070fe0 sp=0xc000070f50 pc=0x4ae491
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000070fe8 sp=0xc000070fe0 pc=0x4feb41
created by runtime.gcBgMarkStartWorkers
/usr/local/go/src/runtime/mgc.go:1159 +0x25

goroutine 21 [GC worker (idle)]:
runtime.gopark(0x176360c288396?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000071750 sp=0xc000071730 pc=0x4cd336
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0000717e0 sp=0xc000071750 pc=0x4ae491
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000717e8 sp=0xc0000717e0 pc=0x4feb41
created by runtime.gcBgMarkStartWorkers
/usr/local/go/src/runtime/mgc.go:1159 +0x25

goroutine 22 [GC worker (idle)]:
runtime.gopark(0x176360c285736?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000071f50 sp=0xc000071f30 pc=0x4cd336
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1235 +0xf1 fp=0xc000071fe0 sp=0xc000071f50 pc=0x4ae491
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000071fe8 sp=0xc000071fe0 pc=0x4feb41
created by runtime.gcBgMarkStartWorkers
/usr/local/go/src/runtime/mgc.go:1159 +0x25

goroutine 8 [GC worker (idle)]:
runtime.gopark(0x176360c285829?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000076f50 sp=0xc000076f30 pc=0x4cd336
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1235 +0xf1 fp=0xc000076fe0 sp=0xc000076f50 pc=0x4ae491
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000076fe8 sp=0xc000076fe0 pc=0x4feb41
created by runtime.gcBgMarkStartWorkers
/usr/local/go/src/runtime/mgc.go:1159 +0x25

goroutine 23 [GC worker (idle)]:
runtime.gopark(0x20915a0?, 0x1?, 0xbf?, 0xba?, 0x0?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000072750 sp=0xc000072730 pc=0x4cd336
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0000727e0 sp=0xc000072750 pc=0x4ae491
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000727e8 sp=0xc0000727e0 pc=0x4feb41
created by runtime.gcBgMarkStartWorkers
/usr/local/go/src/runtime/mgc.go:1159 +0x25

goroutine 34 [GC worker (idle)]:
runtime.gopark(0x176360c28572c?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc000508750 sp=0xc000508730 pc=0x4cd336
runtime.gcBgMarkWorker()
/usr/local/go/src/runtime/mgc.go:1235 +0xf1 fp=0xc0005087e0 sp=0xc000508750 pc=0x4ae491
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0005087e8 sp=0xc0005087e0 pc=0x4feb41
created by runtime.gcBgMarkStartWorkers
/usr/local/go/src/runtime/mgc.go:1159 +0x25

goroutine 9 [chan receive]:
runtime.gopark(0x4d3194?, 0xc00008bd68?, 0x25?, 0xa2?, 0xc000054000?)
/usr/local/go/src/runtime/proc.go:363 +0xd6 fp=0xc00008bd18 sp=0xc00008bcf8 pc=0x4cd336
runtime.chanrecv(0xc00007e540, 0x0, 0x1)
/usr/local/go/src/runtime/chan.go:583 +0x49b fp=0xc00008bda8 sp=0xc00008bd18 pc=0x4971fb
runtime.chanrecv1(0x520ac0?, 0xc?)
/usr/local/go/src/runtime/chan.go:442 +0x18 fp=0xc00008bdd0 sp=0xc00008bda8 pc=0x496cf8
github.com/undefinedlabs/go-mpatch.writeDataToPointer(0x520ac0, {0xc00050ae3c, 0xc, 0x17fc740?})
/home/matheus.tessaroli/go/pkg/mod/github.com/undefinedlabs/[email protected]/patcher_unix.go:46 +0xc5 fp=0xc00008be18 sp=0xc00008bdd0 pc=0xd95b45
github.com/undefinedlabs/go-mpatch.applyPatch(0xc000709290)
/home/matheus.tessaroli/go/pkg/mod/github.com/undefinedlabs/[email protected]/patcher.go:142 +0x1b5 fp=0xc00008beb0 sp=0xc00008be18 pc=0xd95495
github.com/undefinedlabs/go-mpatch.PatchMethod({0x12bf440, 0x14903b0}, {0x12bf440, 0x148e740})
/home/matheus.tessaroli/go/pkg/mod/github.com/undefinedlabs/[email protected]/patcher.go:42 +0x12f fp=0xc00008bee8 sp=0xc00008beb0 pc=0xd94d2f
gitlab.olist.io/channels/integrations/channels-integrations/internal/pkg/channels/via/orders/outbound_test.TestAdapter_GetOlistOrder(0x0?)
/home/matheus.tessaroli/Documentos/channels-integrations/internal/pkg/channels/via/orders/outbound/adapter_test.go:128 +0x4b fp=0xc00008bf70 sp=0xc00008bee8 pc=0xda180b
testing.tRunner(0xc000103d40, 0x148e748)
/usr/local/go/src/testing/testing.go:1446 +0x10b fp=0xc00008bfc0 sp=0xc00008bf70 pc=0x5b018b
testing.(*T).Run.func1()
/usr/local/go/src/testing/testing.go:1493 +0x2a fp=0xc00008bfe0 sp=0xc00008bfc0 pc=0x5b102a
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc00008bfe8 sp=0xc00008bfe0 pc=0x4feb41
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1493 +0x35f

rax 0x17
rbx 0x143d636
rcx 0x5003d5
rdx 0x17
rdi 0x2
rsi 0x143d636
rbp 0x7ffd111ad528
rsp 0x7ffd111ad4f0
r8 0x0
r9 0x0
r10 0x7f8e3bbc9658
r11 0x246
r12 0xc000040900
r13 0x0
r14 0x20571c0
r15 0xffffffffffffffff
rip 0x4fe9a2
rflags 0x206
cs 0x33
fs 0x0
gs 0x0
FAIL gitlab.olist.io/channels/integrations/channels-integrations/internal/pkg/channels/via/orders/outbound 0.016s
FAIL

And as I said, in previous version this doesnt happen

@tonyredondo
Copy link
Contributor

I can't reproduce the issue with your block of code, can you send me a repro case? and the go version?

@mamazinho
Copy link
Author

@tonyredondo unfortunately I can`t share the real code/case because is a private company, the go version is 1.19 and the line that causes the error is https://github.com/undefinedlabs/go-mpatch/blob/master/patcher_unix.go#L46.

This is the difference between two versions. If I remove it in 1.0.7 I can mock normally as in 1.0.6. The code we are mocking is exactly what I passed and my system info is:

image

@evsamsonov
Copy link

I have same issue. Go 1.21.5, go-mpatch = 1.0.7.

	patch, err := mpatch.PatchMethod(time.Now, func() time.Time {
		return parseDateTime("2022-02-22T16:12:31+00:00")
	})
	assert.NoError(t, err)
	defer func() { assert.NoError(t, patch.Unpatch()) }()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants