Skip to content

NH-4092 - AsyncGenerator creates unused private static event handler in SQLite20Driver #712

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

Merged
merged 2 commits into from
Oct 12, 2017

Conversation

ngbrown
Copy link
Contributor

@ngbrown ngbrown commented Oct 10, 2017

Addresses NH-4092.

Exclude SQLite20Driver.Connection_StateChange in AsyncGenerator.yml and regenerate async files.

If it is ok for the Connection.StateChange event to call a fire-and-forget event handler, then the primary event handler method can be modified to an async void.

/// <exception cref="Exception">
/// If there is any problem creating or opening the <see cref="DbConnection"/>.
/// </exception>
public override async Task<DbConnection> GetConnectionAsync(CancellationToken cancellationToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this went away. It still uses conn.OpenAsync

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know. There may be some issues in the AsyncGenerator. I tried various ways to try to exclude SQLite20Driver from being generated and it always made all these changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maca88 can you please investigate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maca88 There is this warning in the generate-async task log on the current master branch (before these changes):

     [exec] INFO  ProjectAnalyzer:0 - Analyzing documents started
     [exec] WARN  ProjectAnalyzer:0 - Cannot attach an async method to an event (void async is not an option as cannot be awaited):
     [exec] connection.StateChange += Connection_StateChange
     [exec] 
     [exec] INFO  ProjectAnalyzer:0 - Analyzing documents completed

What is the correct way to keep the un-used/un-needed private static method from being generated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the correct way to keep the un-used/un-needed private static method from being generated?

Currently, the generator is not smart enough to skip generating un-used private methods, I will try to add support for it.
For un-needed methods, you have to add them in the configuration as you did, but it seems that for this particular method something is not right as GetConnectionAsync is removed even if there is still one async method used (OpenAsync). I will investigate it when I get home.

Copy link
Contributor

@maca88 maca88 Oct 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added support for skipping the generation of unused methods, just by updating to the new version 0.5.1 the method Connection_StateChange won't be generated anymore.

Here is why the GetConnectionAsync goes away when ignoring Connection_StateChange:

With the current settings GetConnection has the conversion set to Unknown when the generator starts scanning, which means that the generator will convert this method to async only if one of the async marked method is called/referenced inside GetConnection method.
Before this change, the GetConnection was generated because of the following dependencies:

  1. IBatcher.ExecuteNonQuery which has the conversion set to Async within the configuration
  2. Inside IBatcher.ExecuteNonQuery method body, DbCommand.ExecuteNonQuery was found to have an async counterpart
  3. SQLite20Driver.Connection_StateChange was found because uses the DbCommand.ExecuteNonQuery method
  4. SQLite20Driver.CreateConnection was found because uses the Connection_StateChange method
  5. DriverConnectionProvider.GetConnection was found beause uses IConnectionProvider.CreateConnection
  6. Inside DriverConnectionProvider.GetConnection method body, DbConnection.Open was found to have an async counterpart

By ignoring SQLite20Driver.Connection_StateChange method, the generator will stop at point 3, which means that DriverConnectionProvider.GetConnection will never be scanned and consequently not generated. So the solution (if we ignore the new version) would be, to set the conversion of GetConnection method to Async or Smart in order to have its method body scanned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @maca88 for the quick turn-around on this. Updating to the new version found a few more un-used private functions that were being generated.

@hazzik hazzik added the t: Bug label Oct 10, 2017
@hazzik hazzik added this to the 5.0.1 milestone Oct 12, 2017
@hazzik hazzik merged commit 8bc7067 into nhibernate:master Oct 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants