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

Fix #1958
I feel some redundancy here. Maybe it is worth reviewing the other counters and state indicators.