Skip to content

Callback into behavioral interface implementation fails from async context #3917

@mrgrain

Description

@mrgrain

Describe the bug

Given the following code:

#!/usr/bin/env python3
import builtins
import typing
import jsii
import aws_cdk as cdk
import aws_cdk.aws_sqs as sqs
from aws_cdk.cli_lib_alpha import AwsCdkCli, ICloudAssemblyDirectoryProducer

@jsii.implements(ICloudAssemblyDirectoryProducer)
class CliProducer:
    def produce(self, context: typing.Mapping[builtins.str, typing.Any]) -> builtins.str:
        app = cdk.App()
        stack = cdk.Stack(app, 'Default')
        sqs.Queue(stack, 'Queue')
        return app.synth().directory


cli = AwsCdkCli.from_cloud_assembly_directory_producer(producer=CliProducer())
cli.list()

Current Behavior

jsii fails with

  File "/Users/abc/.pyenv/versions/3.10.5/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Exception ignored in atexit callback: <bound method _NodeProcess.stop of <jsii._kernel.providers.process._NodeProcess object at 0x10c53ffd0>>
Traceback (most recent call last):
  File "/Users/abc/code/scratchpad/cli-lib/python/.venv/lib/python3.10/site-packages/jsii/_kernel/providers/process.py", line 295, in stop
    self._process.stdin.close()
BrokenPipeError: [Errno 32] Broken pipe

Reproduction Steps

Using these requirements.txt:

aws-cdk-lib==2.61.0
constructs>=10.0.0,<11.0.0
pytest==6.2.5
black>=22.6.0
aws-cdk.cli-lib-alpha==2.61.0a0

Possible Solution

No response

Additional Information/Context

Last part of JSII_DEBUG just before the error:

[@jsii/kernel] callbacks
< {"ok":{"callbacks":[]}}
> {"promiseid":"jsii::promise::20000","api":"end"}
[@jsii/kernel] end jsii::promise::20000
waiting for promise to be fulfilled
[@jsii/kernel] invoke async method override { method: 'produce', property: null, cookie: 'produce' }
[@jsii/kernel] deserialize {
  'aws:cdk:enable-path-metadata': true,
  'aws:cdk:enable-asset-metadata': true,
  'aws:cdk:version-reporting': true,
  'aws:cdk:bundling-stacks': []
} [
  {
    serializationClass: 'Map',
    typeRef: { name: 'context', type: [Object] }
  }
]
[@jsii/kernel] deserialize true [ { serializationClass: 'Any', typeRef: { type: [Object] } } ]
[@jsii/kernel] ANY is a Scalar
[@jsii/kernel] deserialize true [ { serializationClass: 'Any', typeRef: { type: [Object] } } ]
[@jsii/kernel] ANY is a Scalar
[@jsii/kernel] deserialize true [ { serializationClass: 'Any', typeRef: { type: [Object] } } ]
[@jsii/kernel] ANY is a Scalar
[@jsii/kernel] deserialize [] [ { serializationClass: 'Any', typeRef: { type: [Object] } } ]
[@jsii/kernel] ANY is an Array
[@jsii/kernel] adding callback to queue jsii::callback::20001

SDK version used

jsii-1.73.0

Environment details (OS name and version, etc.)

MacOS

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.p2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions