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

System.NullReferenceException when using Oracle #791

Closed
fernandolamp opened this issue Mar 26, 2020 · 7 comments · Fixed by #795
Closed

System.NullReferenceException when using Oracle #791

fernandolamp opened this issue Mar 26, 2020 · 7 comments · Fixed by #795
Labels
bug Something isn't working

Comments

@fernandolamp
Copy link

Describe the bug
Hi guys,
I am using oracle with devart provider and my string connection is:

Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.21.25.186)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCLCDB)));User Id=SAJDDL; Direct=True;

When I try to get data from database, elastic apm throws a exception:

System.NullReferenceException: Object reference not set to an instance of an object.
at Elastic.Apm.Model.DbSpanCommon.GetDestination(String dbConnectionString, Boolean isEmbeddedDb, Nullable1 defaultPort) at Elastic.Apm.Model.DbSpanCommon.EndSpan(Span span, IDbCommand dbCommand, Nullable1 duration)
at Elastic.Apm.EntityFrameworkCore.EfCoreDiagnosticListener.OnNext(KeyValuePair`2 kv)
at System.Diagnostics.DiagnosticListener.Write(String name, Object value)

The problem happen in this method:

    internal Destination GetDestination(
      string dbConnectionString,
      bool isEmbeddedDb,
      int? defaultPort)
    {
      if (isEmbeddedDb || dbConnectionString == null)
        return (Destination) null;
      Destination destination = this._dbConnectionStringParser.ExtractDestination(dbConnectionString);
      if (!destination.Port.HasValue)  <----- HERE
        destination.Port = defaultPort;
      return destination;
    }

Below I try explain why this happened:

Debuging:

In DbSpanCommon.cs:
internal Destination GetDestination
image

My string connection:
image

DbConnectionStringParser.cs:
image

When try to extract destination, I noticed that the value of "key/value" pair is null:
image

image

The key is found but destination is null, and when he try to access destination.Port.HasValue:

image

The exception is thrown.

To Reproduce
Steps to reproduce the behavior:

  1. Configure oracle string connection like this: Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.21.25.186)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCLCDB)));User Id=SAJDDL; Direct=True;

  2. Try to retrieve value from database

Expected behavior

Find database destination and don´t throw NullPointReference exception

Thank you in advance, elastic apm is awesome!

@fernandolamp fernandolamp added the bug Something isn't working label Mar 26, 2020
@fernandolamp
Copy link
Author

After update to version 1.4.0 the problem was solved

@SergeyKleyman
Copy link
Contributor

SergeyKleyman commented Mar 26, 2020

@fernandolamp Could you please double check if indeed 1.4.0 resolves your issue? While we did include a fix (#749) for another issue (#746) in DB connection string parser I am not sure that fix could have done anything to resolve your issue.

@Cesaragsilva
Copy link

@SergeyKleyman and @gregkalapos the problem are occurring in .net core 2.2 with oracle yet, can you check again?

i'm using the last version of the package.

@gregkalapos
Copy link
Contributor

@SergeyKleyman and @gregkalapos the problem are occurring in .net core 2.2 with oracle yet, can you check again?

i'm using the last version of the package.

@Cesaragsilva could you give us the logs? Especially the callstack would be interesting. Given that the code changed in this area I expect a different callstack - but let's see...

@SergeyKleyman
Copy link
Contributor

Please correct me if I am wrong - the fix (#795) is not included in the latest (which is at the moment 1.4.0) release.

@gregkalapos
Copy link
Contributor

Please correct me if I am wrong - the fix (#795) is not included in the latest (which is at the moment 1.4.0) release.

😱 Yes, you are right - thanks for pointing this out! #795 was merged after 1.4 was released. Now I remember the full story.

Ok, so, now it makes sense - @Cesaragsilva this will be in the next release which will be out very soon. Sorry about the confusion.

Thanks @SergeyKleyman.

@Cesaragsilva
Copy link

@gregkalapos and @SergeyKleyman Thank you for check it. I'm await the next version eagerly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants