Skip to content

Commit

Permalink
Close conn if exception is thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
SwitchyTheCoder committed Jul 6, 2018
1 parent e41ec72 commit cb20e5d
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions neo-cli/Shell/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,21 +1083,33 @@ private static void WriteToPsql(SmartContractEvent contractEvent)

using (var conn = new NpgsqlConnection(connString))
{
conn.Open();

WriteToEventTable(contractEvent, conn);

if (contractEvent.eventType == "created")
try
{
WriteToOfferTable(contractEvent, conn);
}
conn.Open();

WriteToEventTable(contractEvent, conn);

if (contractEvent.eventType == "created")
{
WriteToOfferTable(contractEvent, conn);
}

if (contractEvent.eventType == "filled")
{
WriteToTradeTable(contractEvent, conn);
}

if (contractEvent.eventType == "filled")
conn.Close();
}
catch (Exception ex)
{
WriteToTradeTable(contractEvent, conn);
if (conn != null && conn.State == System.Data.ConnectionState.Open)
{
conn.Close();
}
throw ex;
}

conn.Close();
}

}
Expand Down

0 comments on commit cb20e5d

Please sign in to comment.