Fix issues that GroupBy and Sample doesn't call 'unsubscribe' and also NPE when the key is null in GroupBy

Fix #1958
Found a race condition. I used a lock to fix it... Any suggestion for a lock-free approach?