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

x/crypto/scrypt: memory not released after hash is calculated #40687

Closed
cheng762 opened this issue Aug 11, 2020 · 2 comments
Closed

x/crypto/scrypt: memory not released after hash is calculated #40687

cheng762 opened this issue Aug 11, 2020 · 2 comments

Comments

@cheng762
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.14.1 linux/amd64

What did you do?

when I concurrent call scrypt.Key ,the memory not released after FreeOSMemory,here is the code

package main

import (
	"fmt"
	"log"
	"runtime/debug"
	"time"

	"golang.org/x/crypto/scrypt"
)

func main() {
	for i := 0; i < 30; i++ {
		go func() {
			key, _ := scrypt.Key(
				[]byte(""), // Input data.
				[]byte(""), // Salt.
				1<<18,      // Scrypt parameter N.
				16,         // Scrypt parameter r.
				1,          // Scrypt parameter p.
				64)         // Output hash length.

			fmt.Println(key)
		}()
	}

	time.Sleep(20 * time.Second)
	log.Println("free")
	debug.FreeOSMemory()

	// Keep the process running.
	time.Sleep(500 * time.Second)
}

@gopherbot gopherbot added this to the Unreleased milestone Aug 11, 2020
@davecheney
Copy link
Contributor

davecheney commented Aug 11, 2020

@cheng762 under linux we can only ask the operating system to take back memory from the processes address space, we cannot tell the operating system to do this. The operating system can, and often does, ignore this request unless it is under memory pressure from other processes.

You can verify that the scavenger ran by exporting this environment variable GODEBUG=gctrace=1 and running your process again. You will probably have to increase the amount of time to wait.

@andybons
Copy link
Member

@davecheney is correct. Closing for now as there does not seem to be anything to do. Please feel free to comment if you feel otherwise.

@golang golang locked and limited conversation to collaborators Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants