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

STAThread and OracleConnection.OpenAsync #427

Open
FJGR65 opened this issue Dec 12, 2024 · 6 comments
Open

STAThread and OracleConnection.OpenAsync #427

FJGR65 opened this issue Dec 12, 2024 · 6 comments
Labels

Comments

@FJGR65
Copy link

FJGR65 commented Dec 12, 2024

(ODP NET 23.6.1 with .NET Framework 4.8) OracleConnection.OpenAsync does not work when we have a WPF (STAThread) application. The application hangs when trying to open the connection asynchronously.

`
OracleConnection cn = new OracleConnection("DATA SOURCE=XXXXXX:1521/XE;PASSWORD=YYYYY;USER ID=ZZZZZ");

  //The application does indeed open the connection, but hangs when trying to return to the main process.
  //await cn.OpenAsync().ConfigureAwait(false); // The application hangs

  //Solution:
  await Task.Run(async () => await cn.OpenAsync().ConfigureAwait(false)).ConfigureAwait(false);

  Thread.Sleep(1000);
  cn.Close();
  cn = null;

`

Viewing the end of trace file:

2024-12-12 12:22:57.943403 TID:5 (PRI) (EXT) (CID1) OracleConnection.OnConnectionOpen()
2024-12-12 12:22:57.949574 TID:5 (PRI) (ENT) (CID1) OracleConnectionImpl.InitializeDBSvcProperties()
2024-12-12 12:22:57.949574 TID:5 (PRI) (CID1) DB Svc AC Properties =>
2024-12-12 12:22:57.949574 TID:5 (PRI) (CID1) Application Continuity (AC/TAC) NOT Enabled on the connection
2024-12-12 12:22:57.960385 TID:5 (PRI) (SVC) (ENT) (CID1) OracleConnectionImpl.InitializeTAF()
2024-12-12 12:22:57.960385 TID:5 (PRI) (SVC) (CID1) TAF disabled through FAILOVER_TYPE=NONE configured on the connection string
2024-12-12 12:22:57.960385 TID:5 (PRI) (SVC) (EXT) (CID1) OracleConnectionImpl.InitializeTAF()
2024-12-12 12:22:57.961997 TID:5 (PRI) (SVC) (ENT) (CID1) OracleTransactionImpl.ctor()
2024-12-12 12:22:57.961997 TID:5 (PRI) (SVC) (EXT) (CID1) OracleTransactionImpl.ctor()
2024-12-12 12:22:57.961997 TID:5 (PRI) (SVC) (ENT) (CID1) OracleConnectionImpl.SetAutoCommit()
2024-12-12 12:22:57.961997 TID:5 (PRI) (SVC) (EXT) (CID1) OracleConnectionImpl.SetAutoCommit()
2024-12-12 12:22:57.966456 TID:5 (PRI) (SVC) (ENT) OracleGlobalizationImpl.GetLocaleSpecificNLSValues() Connecting with session time zone as :Europe/Paris
2024-12-12 12:22:57.972639 TID:5 (PRI) (ENT) (CID1) OracleConnection.OnStateChange()
2024-12-12 12:22:57.972639 TID:5 (PRI) (EXT) (CID1) OracleConnection.OnStateChange()
2024-12-12 12:22:57.972639 TID:5 (PRI) (CP) (CID1) OracleConnection.Open() (GET) (ENDSID=13:54549)
2024-12-12 12:22:57.973770 TID:5 (PUB) (EXT) (CID1) OracleConnection.OpenInternal() (conid=36328474) (state=Open) (sessid=13) (implid=49538252) (pooling=T) (CID1) (aff=n/a) (inst=xe) (affmatch=n/a) (pr.service=xe) (pr.pdb=) (pr.edition=) (sessid=13:54549) (T;F;F;xe;N) (pmid=47542785) (DISP) (service=xe;inst=xe;used=1;idle=0;tot=1)
2024-12-12 12:22:57.973770 TID:5 (PUB) (EXT) (CID1) OracleConnection.OpenAsyncHelper() //Hangs

@alexkeh
Copy link
Member

alexkeh commented Dec 12, 2024

I don't typically work with Windows Forms. Can you share a complete test case with the hanging behavior? The ODP.NET team and I can review it. It probably has something to do with using single-threaded apartments with ODP.NET async.

@FJGR65
Copy link
Author

FJGR65 commented Dec 13, 2024

The project is quite complex, since depending on the arguments in the program call, it can work as a console application or as a WPF (Windows Presentation Fundation) application. This project is almost entirely asynchronous, and has been working correctly with Oracle.ManagedDataAccess 21.x correctly, although I know that the methods are not asynchronous. However, when testing with version 23.x it hangs when establishing the connection.

I have tried to make a simple project, but in this simple project the mentioned error does not occur.

I just wanted to point out that when this error occurs, I have found this alternative solution.

@FJGR65
Copy link
Author

FJGR65 commented Dec 13, 2024

I have created a simple Windows Forms project where the above occurs.

ConsoleApp3.zip

@alexkeh
Copy link
Member

alexkeh commented Dec 13, 2024

@FJGR65 Can you re-zip your Windows Forms app? I'm getting errors unzipping it.

@FJGR65
Copy link
Author

FJGR65 commented Dec 14, 2024

Sorry, I packed it with "7z" with some non-standard parameters. I'll upload it again and hope there won't be any problems unzipping it.

ConsoleApp3.zip

@alexkeh
Copy link
Member

alexkeh commented Dec 15, 2024

@FJGR65 Thanks for the straightforward test case. I was able to reproduce the hang you experienced. I've filed Bug 37395788 for the ODP.NET team to review the test case and diagnose the problem.

@alexkeh alexkeh added the bug label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants