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

OOM after multiple calls (mac air M1) (go1.21.4 darwin/arm64) #397

Open
loadgame opened this issue Nov 15, 2023 · 1 comment
Open

OOM after multiple calls (mac air M1) (go1.21.4 darwin/arm64) #397

loadgame opened this issue Nov 15, 2023 · 1 comment

Comments

@loadgame
Copy link

loadgame commented Nov 15, 2023

main.go

package main

import (
	"log/slog"
	"runtime"

	"rogchap.com/v8go"
)

var ctx *v8go.Context

func runJavascript(script string) string {
	val, err := ctx.RunScript(script, "test.js")
	if err != nil {
		slog.Error("error", "val", val, "err", err)
	}
	return val.String()
}

func main() {
	ctx = v8go.NewContext()
	defer ctx.Close()
	runJavascript(`

		function test(jsonStr) {
			var jsonObj = JSON.parse(jsonStr);
			jsonObj.type = "test"
			var jsonStr = JSON.stringify(jsonObj);
			return jsonStr;
		}

	`)
	var res string
	for i := 0; i < 100000000; i++ {
		res = runJavascript(`test('{"value":"empty"}')`)
		if i%1000000 == 0 {
			slog.Warn("TestVM & golang GC", "res", res, "i", i)
			runtime.GC()
		}
	}
}

log below


023/11/15 20:25:22 WARN TestVM & golang GC res="{\"value\":\"empty\",\"type\":\"test\"}" i=18000000

<--- Last few GCs --->

[85430:0x130008000]    93664 ms: Mark-Compact 1377.1 (1442.6) -> 1363.5 (1445.1) MB, 801.6 / 0.0 ms  (average mu = 0.335, current mu = 0.213) allocation failure; scavenge might not succeed
[85430:0x130008000]    95239 ms: Mark-Compact 1380.9 (1446.6) -> 1367.5 (1449.1) MB, 1315.9 / 0.0 ms  (average mu = 0.239, current mu = 0.164) allocation failure; scavenge might not succeed


<--- JS stacktrace --->


#
# Fatal javascript OOM in Reached heap limit
#

SIGTRAP: trace trap
PC=0x104e36750 m=8 sigcode=0
signal arrived during cgo execution

goroutine 1 [syscall]:
runtime.cgocall(0x104e156b0, 0x1400005fcd8)
        /usr/local/go/src/runtime/cgocall.go:157 +0x44 fp=0x1400005fca0 sp=0x1400005fc60 pc=0x104d5f0f4
rogchap.com/v8go._Cfunc_ValueToString(0x37889ea80)
        _cgo_gotypes.go:2173 +0x3c fp=0x1400005fcd0 sp=0x1400005fca0 pc=0x104e107cc
rogchap.com/v8go.(*Value).String.func1(0x1400005fe08?)
        /Users/peter/go/pkg/mod/rogchap.com/v8go@v0.9.0/value.go:242 +0x60 fp=0x1400005fd70 sp=0x1400005fcd0 pc=0x104e12840
rogchap.com/v8go.(*Value).String(0x1400000e030?)
        /Users/peter/go/pkg/mod/rogchap.com/v8go@v0.9.0/value.go:242 +0x2c fp=0x1400005fe10 sp=0x1400005fd70 pc=0x104e126bc
main.runJavascript({0x105cce45d?, 0x19?})
        /vm_oom/main.go:17 +0xc4 fp=0x1400005fe90 sp=0x1400005fe10 pc=0x104e13114
main.main()
        /vm_oom/main.go:37 +0xc0 fp=0x1400005ff30 sp=0x1400005fe90 pc=0x104e13200
runtime.main()
        /usr/local/go/src/runtime/proc.go:267 +0x2bc fp=0x1400005ffd0 sp=0x1400005ff30 pc=0x104d9188c
runtime.goexit()
        /usr/local/go/src/runtime/asm_arm64.s:1197 +0x4 fp=0x1400005ffd0 sp=0x1400005ffd0 pc=0x104dbe784



@loadgame loadgame changed the title OOM after multiple calls (mac book air M1) (go version go1.21.4 darwin/arm64) OOM after multiple calls (mac air M1) (go1.21.4 darwin/arm64) Nov 20, 2023
@loadgame loadgame reopened this Nov 20, 2023
@krvajal
Copy link

krvajal commented Jan 22, 2024

This seems to fix the issue

func runJavascript(script string) string {
	val, err := ctx.RunScript(script, "test.js")
	defer val.Release() // <= release the value
	if err != nil {
		slog.Error("error", "val", val, "err", err)
	}
	return val.String()
}

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

2 participants