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

Singlethons populated inside GeneratorTask is inaccessible from CompilerLifecycleTask #34296

Closed
xlight05 opened this issue Dec 13, 2021 · 4 comments
Assignees
Labels
Area/ProjectAPI Priority/High Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Bug

Comments

@xlight05
Copy link
Contributor

Description:
In Azure functions and AWS Lambda functions modules, we generate the source file inside GeneratorTask class. We use the same data model inside CompilerLifecycleTask phase so we store it in a singlethon class as a cache. For some reason in latest pack, Singlethon class seems to be empty when CompilerLifecycleTask phase is reached.

Steps to reproduce:
https://github.com/xlight05/module-ballerinax-azure.functions/tree/stripped-ext

you can make the pack by executing ./gradlew clean build . It'll be created in /azurefunctions-extension-bala azurefunctions-extension-bala/build/extracted-distribution.

Test case is available at azurefunctions-extension-test/src/test/resources/deployment

You can do BAL_JAVA_DEBUG=5005 /azurefunctions-extension-bala/build/extracted-distribution/jballerina-tools-2.0.0-beta.6-20211211-193900-8a474932/bin/bal build
to debug.

extension source- , azurefunctions-extension

You can observe the value of TestSinglethon using the above sample.
Affected Versions:

OS, DB, other environment details and versions:

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

@azinneera
Copy link
Contributor

azinneera commented Dec 14, 2021

@xlight05 I tested this with a simple Singleton class with Beta.6 RC2 pack but didn't encounter any issues. Here is the scenario I tried:

  1. Added a Singleton class to the compiler plugin package with the public field timestamp
  2. Access the singleton and set the current timestamp in a codeGenerator task
  3. Verify the timestamp in the CompilreLifeCycleTask

The source code of the plugin and the Singleton can be found here: https://gist.github.com/azinneera/2288815f83fe2e8b03cd762f7047c6fe

This is the output I got:

Compiling source
	user/foo:0.1.0
Before update:0
After update in codegen task:1639462777872
WARNING [main.bal:(18:9,18:13)] no such documentable parameter 'name'
WARNING [main.bal:(20:5,20:5)] concurrent calls will not be made to this method since the method is not an 'isolated' method
WARNING [main.bal:(25:9,27:12)] unused variable 'e'
WARNING [main.bal:(34:9,34:155)] unused variable 'executeResponse'

Generating executable
Compiler lifecycle event ctx:1639462777872
	target/bin/foo.jar

I dont see any issues in the functionality of the singleton. Please let us know if your scenario is different

@azinneera
Copy link
Contributor

The above was tested with an in-built compiler plugin. Was able to reproduce the issue with a package-provided compiler plugin.

@azinneera
Copy link
Contributor

azinneera commented Feb 14, 2023

This is the expected behavior since the classloaders are different for the analysis and lifecycle phases. The suggested approach to pass information is to persist to the target/ directory and access it.

@github-actions
Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/ProjectAPI Priority/High Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Bug
Projects
None yet
Development

No branches or pull requests

3 participants