Skip to content

Commit 87e6169

Browse files
Merge pull request #217 from slorello89/bugfix/swallowed-seralization-errors
removing empty catch.
2 parents 10466fd + 374f1d9 commit 87e6169

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/RedisSessionStateProvider/RedisConnectionWrapper.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,10 @@ private bool TryUpdateAndReleaseLockPrepare(object lockId, ISessionStateItemColl
334334
List<object> list = new List<object>();
335335
int noOfItemsRemoved = 0;
336336
int noOfItemsUpdated = 0;
337-
try
338-
{
339-
byte[] serializedSessionStateItemCollection = SerializeSessionStateItemCollection(data);
340-
list.Add("SessionState");
341-
list.Add(serializedSessionStateItemCollection);
342-
noOfItemsUpdated = 1;
343-
}
344-
catch
345-
{
346-
}
337+
byte[] serializedSessionStateItemCollection = SerializeSessionStateItemCollection(data);
338+
list.Add("SessionState");
339+
list.Add(serializedSessionStateItemCollection);
340+
noOfItemsUpdated = 1;
347341

348342
keyArgs = new string[] { Keys.LockKey, Keys.DataKey, Keys.InternalKey };
349343
valueArgs = new object[list.Count + 8]; // this +8 is for first wight values in ARGV that we will add now

test/RedisSessionStateProviderUnitTest/RedisConnectionWrapperTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Configuration;
99
using System.IO;
1010
using System.Threading;
11+
using System.Web;
1112
using System.Web.SessionState;
1213
using Xunit;
1314

@@ -246,6 +247,22 @@ public void TryRemoveIfLockIdMatch_Valid()
246247
A.CallTo(() => redisConn.redisConnection.Eval(A<string>.Ignored, A<string[]>.That.Matches(s => s.Length == 3),
247248
A<object[]>.That.Matches(o => o.Length == 1))).MustHaveHappened();
248249
}
250+
251+
[Fact]
252+
public void TrySetObjectNotMarkedSerializable()
253+
{
254+
string id = "session_id";
255+
int sessionTimeout = 900;
256+
object lockId = DateTime.Now.Ticks;
257+
SessionStateItemCollection data = new SessionStateItemCollection();
258+
data["Key"] = new {Name = "Hal"}; // try to add anon type, this will throw a serialization error when you try to commit it as the type is not marked as serializable.
259+
260+
RedisConnectionWrapper.sharedConnection = A.Fake<RedisSharedConnection>();
261+
RedisConnectionWrapper redisConn = new RedisConnectionWrapper(Utility.GetDefaultConfigUtility(), id);
262+
redisConn.redisConnection = A.Fake<IRedisClientConnection>();
263+
var exception = Assert.Throws<HttpException>(() =>redisConn.TryUpdateAndReleaseLock(lockId, data, sessionTimeout));
264+
Assert.Contains("Unable to serialize the session state.", exception.Message);
265+
}
249266

250267
[Fact]
251268
public void TryUpdateIfLockIdMatchPrepare_NoUpdateNoDelete()

0 commit comments

Comments
 (0)