• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Giorgi / DuckDB.NET / 44399310985

18 Nov 2026 09:13PM UTC coverage: 93.588% (-0.05%) from 93.639%
44399310985

push

github

Giorgi
Bump actions/setup-java from 6.2.0 to 6.3.0 in the github-actions group

Bumps the github-actions group with 1 update: [actions/setup-java](https://github.com/actions/setup-java).


Updates `actions/setup-java` from 6.2.0 to 6.3.0
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](https://github.com/actions/setup-java/compare/77dd5b2ce...d1374f8ac)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-version: 6.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>

2849 of 3093 branches covered (92.11%)

Branch coverage included in aggregate %.

4478 of 4736 relevant lines covered (94.55%)

1018654.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.83
/DuckDB.NET.Data/Connection/ConnectionManager.cs
1
using System.Collections.Concurrent;
2
using System.Threading;
3

4
namespace DuckDB.NET.Data.Connection;
5

6
/// <summary>
7
/// Creates, caches, and disconnects ConnectionReferences.
8
/// </summary>
9
internal class ConnectionManager
10
{
11
    public static readonly ConnectionManager Default = new();
3 ✔
12

13
    private static readonly ConcurrentDictionary<string, FileReference> ConnectionCache = new(StringComparer.OrdinalIgnoreCase);
3 ✔
14

15
    internal ConnectionReference GetConnectionReference(DuckDBConnectionString connectionString)
16
    {
17
        var filename = connectionString.DataSource;
564 ✔
18

19
        var fileRef = connectionString.InMemory && !connectionString.Shared ? new FileReference("") : null;
564 ✔
20

21
        //need to loop until we have a locked fileRef
22
        //that is also in the cache
23
        while (fileRef == null)
564 ✔
24
        {
25
            fileRef = ConnectionCache.GetOrAdd(filename, fn =>
129 !
26
            {
129 ✔
27
                fileRef = new FileReference(filename);
63 ✔
28
                return fileRef;
63 ✔
29
            });
129 ✔
30

31
            Monitor.Enter(fileRef);
129 ✔
32

33
            //Need to make sure what we have locked is still in the cache
34
            var existingFileRef = ConnectionCache.GetOrAdd(filename, fileRef);
129 ✔
35

36
            if (existingFileRef == fileRef)
129 !
37
            {
38
                //file in the cache matches what is locked, we are good!
39
                break;
40
            }
41

42
            //exit lock and try the whole thing again
43
            Monitor.Exit(fileRef);
×
44
            fileRef = null;
×
45
        }
46

47
        //now connect what needs to be connected
48
        try
49
        {
50
            if (fileRef.Database == null)
564 ✔
51
            {
52
                var path = connectionString.InMemory ? null : filename;
498 ✔
53

54
                NativeMethods.Configuration.DuckDBCreateConfig(out var config);
498 ✔
55
                using (config)
498 ✔
56
                {
57
                    foreach (var (option, value) in connectionString.Configuration)
2,358 ✔
58
                    {
59
                        var state = NativeMethods.Configuration.DuckDBSetConfig(config, option, value);
687 ✔
60

61
                        if (!state.IsSuccess())
687 ✔
62
                        {
63
                            throw new DuckDBException($"Error setting '{option}' to '{value}'");
12 ✔
64
                        }
65
                    }
66

67
                    var resultOpen = NativeMethods.Startup.DuckDBOpen(path, out var db, config, out var error);
486 ✔
68

69
                    if (!resultOpen.IsSuccess())
486 !
70
                    {
71
                        throw new DuckDBException($"DuckDBOpen failed: {error}");
×
72
                    }
73
                    fileRef.Database = db;
486 ✔
74
                }
486 ✔
75
            }
76

77
            var resultConnect = NativeMethods.Startup.DuckDBConnect(fileRef.Database, out var nativeConnection);
552 ✔
78

79
            if (resultConnect.IsSuccess())
552 !
80
            {
81
                fileRef.Increment();
552 ✔
82
            }
83
            else
84
            {
85
                throw new DuckDBException("DuckDBConnect failed");
×
86
            }
87

88
            return new ConnectionReference(fileRef, nativeConnection);
552 ✔
89
        }
90
        finally
91
        {
92
            if (Monitor.IsEntered(fileRef))
564 ✔
93
            {
94
                Monitor.Exit(fileRef);
129 ✔
95
            }
96
        }
564 ✔
97
    }
552 ✔
98

99
    internal void ReturnConnectionReference(ConnectionReference connectionReference)
100
    {
101
        var fileRef = connectionReference.FileReferenceCounter;
549 ✔
102

103
        lock (fileRef)
549 ✔
104
        {
105
            var nativeConnection = connectionReference.NativeConnection;
549 ✔
106

107
            nativeConnection.Dispose();
549 ✔
108

109
            var current = fileRef.Decrement();
549 ✔
110

111
            if (current < 0)
549 !
112
            {
113
                throw new InvalidOperationException($"{fileRef.FileName} has been returned too many times");
×
114
            }
115

116
            if (current == 0)
549 ✔
117
            {
118
                fileRef.Database?.Dispose();
480 !
119
                fileRef.Database = null;
480 ✔
120

121
                if (!string.IsNullOrEmpty(fileRef.FileName) && !ConnectionCache.TryRemove(fileRef.FileName, out _))
480 !
122
                {
123
                    throw new InvalidOperationException($"Internal Error: tried to remove {fileRef.FileName} from cache but it wasn't there!");
×
124
                }
125
            }
126
        }
549 ✔
127
    }
549 ✔
128

129
    internal ConnectionReference DuplicateConnectionReference(ConnectionReference connectionReference)
130
    {
131
        var fileRef = connectionReference.FileReferenceCounter;
3 ✔
132

133
        if (fileRef.Database is null)
3 !
134
            throw new InvalidOperationException(); //shouldn't happen if we already have a connection reference
×
135

136
        lock (fileRef)
3 ✔
137
        {
138
            var resultConnect = NativeMethods.Startup.DuckDBConnect(fileRef.Database, out var duplicatedNativeConnection);
3 ✔
139
            if (resultConnect.IsSuccess())
3 !
140
            {
141
                fileRef.Increment();
3 ✔
142
            }
143
            else
144
            {
145
                throw new DuckDBException("DuckDBConnect failed");
×
146
            }
147
            return new ConnectionReference(fileRef, duplicatedNativeConnection);
3 ✔
148
        }
149
    }
3 ✔
150
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc