jsii icon indicating copy to clipboard operation
jsii copied to clipboard

jsii-runtime-go have json unmarshall issue when execute in parallel

Open KaimingWan opened this issue 2 years ago • 0 comments

Describe the bug

My golang app use tfcdk which depend on jsii, you can ref the code here.

If I run my app and start multi goroutine to execute the core logic, I can find the jsii.Create not work as expected. I debug the code and find err is generated in the following code:

func (p *Process) readResponse(into interface{}) error {
	if !p.responses.More() {
		return fmt.Errorf("no response received from child process")
	}

	var raw json.RawMessage
	var respmap map[string]interface{}
	err := p.responses.Decode(&raw)
	if err != nil {
		return err
	}

	err = json.Unmarshal(raw, &respmap)
	if err != nil {
		return err
	}

	var errResp ErrorResponse
	if _, ok := respmap["error"]; ok {
		json.Unmarshal(raw, &errResp)

		if errResp.Name != nil && *errResp.Name == "@jsii/kernel.Fault" {
			return fmt.Errorf("JsiiError: %s", *errResp.Name)
		}

		return errors.New(errResp.Error)
	}

	return json.Unmarshal(raw, &into)
}

err in p.responses give the json unmarshall error:

invalid character 'j' looking for beginning of value

Is this issue a bug or we can't execute jsii.Create in parallel ?

Expected Behavior

jsii.Create can be executed in parallel

Current Behavior

When execute jsii.Create in parallel, will cause json unmarshall issue

Reproduction Steps

Just startup multi goroutines and init and execute cdktf which will invoke jsii.Create in parallel

Possible Solution

No response

Additional Information/Context

No response

SDK version used

v1.81.0

Environment details (OS name and version, etc.)

5.19.0-0.deb11.2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.19.11-1~bpo11+1 (2022-10-03) x86_64 Linux

KaimingWan avatar Aug 10 '23 06:08 KaimingWan