Skip to content

Commit 0e96f79

Browse files
committed
RecordSetReader: prevent error on finish to overlap original exception
1 parent 4306469 commit 0e96f79

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Orm/Xtensive.Orm/Orm/Rse/RecordSetReader.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ private async ValueTask Prepare(bool executeAsync)
139139
context.SetValue(provider, enumerationMarker, true);
140140
}
141141

142+
bool isOnEnumerateSuccessful = false;
142143
try {
143144
dataReader = executeAsync
144145
? await provider.OnEnumerateAsync(context, token).ConfigureAwait(false)
145146
: provider.OnEnumerate(context);
146147

148+
isOnEnumerateSuccessful = true;
147149
if (isGreedy && !dataReader.IsInMemory) {
148150
var tuples = new List<Tuple>();
149151
if (executeAsync) {
@@ -164,16 +166,30 @@ private async ValueTask Prepare(bool executeAsync)
164166
}
165167
}
166168
catch {
167-
FinishEnumeration(true);
169+
FinishEnumeration(true, !isOnEnumerateSuccessful);
168170
throw;
169171
}
170172
state = State.Prepared;
171173
}
172174

173-
private void FinishEnumeration(bool isError)
175+
private void FinishEnumeration(bool isError, bool isErrorOnServerSide = false)
174176
{
175-
if (!enumerated) {
176-
provider?.OnAfterEnumerate(context);
177+
if (isErrorOnServerSide) {
178+
// Possible connection closing because of server-side error, like operation timeout,
179+
// which makes finish of some providers imposible, like ones that work with tempoerary tables and require clean-up.
180+
// Exception may happen but we must prevent overlaping original exception with new one.
181+
if (!enumerated) {
182+
try {
183+
provider?.OnAfterEnumerate(context);
184+
}
185+
catch {
186+
}
187+
}
188+
}
189+
else {
190+
if (!enumerated) {
191+
provider?.OnAfterEnumerate(context);
192+
}
177193
}
178194

179195
if (!isError) {

0 commit comments

Comments
 (0)