Recover from panics which can get sent from goleveldb due to bad arguments. Closes #1059
This commit is contained in:
parent
1bc63df5f2
commit
ab7b9b914c
|
@ -156,8 +156,19 @@ func (s *WMailServer) Close() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func recoverLevelDBPanics(calleMethodName string) {
|
||||||
|
// Recover from possible goleveldb panics
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
if errString, ok := r.(string); ok {
|
||||||
|
log.Error(fmt.Sprintf("recovered from panic in %s: %s", calleMethodName, errString))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Archive a whisper envelope.
|
// Archive a whisper envelope.
|
||||||
func (s *WMailServer) Archive(env *whisper.Envelope) {
|
func (s *WMailServer) Archive(env *whisper.Envelope) {
|
||||||
|
defer recoverLevelDBPanics("Archive")
|
||||||
|
|
||||||
key := NewDbKey(env.Expiry-env.TTL, env.Hash())
|
key := NewDbKey(env.Expiry-env.TTL, env.Hash())
|
||||||
rawEnvelope, err := rlp.EncodeToBytes(env)
|
rawEnvelope, err := rlp.EncodeToBytes(env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -188,6 +199,8 @@ func (s *WMailServer) DeliverMail(peer *whisper.Peer, request *whisper.Envelope)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer recoverLevelDBPanics("DeliverMail")
|
||||||
|
|
||||||
if ok, lower, upper, bloom := s.validateRequest(peer.ID(), request); ok {
|
if ok, lower, upper, bloom := s.validateRequest(peer.ID(), request); ok {
|
||||||
s.processRequest(peer, lower, upper, bloom)
|
s.processRequest(peer, lower, upper, bloom)
|
||||||
if err := s.sendHistoricMessageResponse(peer, request); err != nil {
|
if err := s.sendHistoricMessageResponse(peer, request); err != nil {
|
||||||
|
|
|
@ -111,7 +111,7 @@ func (s *WhisperMailboxSuite) TestRequestMessageFromMailboxAsync() {
|
||||||
senderWhisperService.SubscribeEnvelopeEvents(events)
|
senderWhisperService.SubscribeEnvelopeEvents(events)
|
||||||
|
|
||||||
// Request messages (including the previous one, expired) from mailbox.
|
// Request messages (including the previous one, expired) from mailbox.
|
||||||
result := s.requestHistoricMessages(senderWhisperService, rpcClient, mailboxPeerStr, MailServerKeyID, topic.String())
|
result := s.requestHistoricMessagesFromLast12Hours(senderWhisperService, rpcClient, mailboxPeerStr, MailServerKeyID, topic.String())
|
||||||
requestID := common.BytesToHash(result)
|
requestID := common.BytesToHash(result)
|
||||||
|
|
||||||
// And we receive message, it comes from mailbox.
|
// And we receive message, it comes from mailbox.
|
||||||
|
@ -282,8 +282,8 @@ func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() {
|
||||||
s.Require().Empty(messages)
|
s.Require().Empty(messages)
|
||||||
|
|
||||||
// Request each one messages from mailbox using enode.
|
// Request each one messages from mailbox using enode.
|
||||||
s.requestHistoricMessages(bobWhisperService, bobRPCClient, mailboxEnode, bobMailServerKeyID, groupChatTopic.String())
|
s.requestHistoricMessagesFromLast12Hours(bobWhisperService, bobRPCClient, mailboxEnode, bobMailServerKeyID, groupChatTopic.String())
|
||||||
s.requestHistoricMessages(charlieWhisperService, charlieRPCClient, mailboxEnode, charlieMailServerKeyID, groupChatTopic.String())
|
s.requestHistoricMessagesFromLast12Hours(charlieWhisperService, charlieRPCClient, mailboxEnode, charlieMailServerKeyID, groupChatTopic.String())
|
||||||
|
|
||||||
// Bob receive p2p message from group chat filter.
|
// Bob receive p2p message from group chat filter.
|
||||||
messages = s.getMessagesByMessageFilterIDWithTracer(bobRPCClient, bobGroupChatMessageFilterID, bobTracer, groupChatMessageHash)
|
messages = s.getMessagesByMessageFilterIDWithTracer(bobRPCClient, bobGroupChatMessageFilterID, bobTracer, groupChatMessageHash)
|
||||||
|
@ -515,11 +515,16 @@ func (s *WhisperMailboxSuite) addSymKey(rpcCli *rpc.Client, symkey string) strin
|
||||||
return symkeyID
|
return symkeyID
|
||||||
}
|
}
|
||||||
|
|
||||||
// requestHistoricMessages asks a mailnode to resend messages.
|
// requestHistoricMessagesFromLast12Hours asks a mailnode to resend messages from last 12 hours.
|
||||||
func (s *WhisperMailboxSuite) requestHistoricMessages(w *whisper.Whisper, rpcCli *rpc.Client, mailboxEnode, mailServerKeyID, topic string) []byte {
|
func (s *WhisperMailboxSuite) requestHistoricMessagesFromLast12Hours(w *whisper.Whisper, rpcCli *rpc.Client, mailboxEnode, mailServerKeyID, topic string) []byte {
|
||||||
currentTime := w.GetCurrentTime()
|
currentTime := w.GetCurrentTime()
|
||||||
from := currentTime.Add(-12 * time.Hour)
|
from := currentTime.Add(-12 * time.Hour)
|
||||||
to := currentTime
|
to := currentTime
|
||||||
|
return s.requestHistoricMessages(w, rpcCli, mailboxEnode, mailServerKeyID, topic, from, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
// requestHistoricMessages asks a mailnode to resend messages.
|
||||||
|
func (s *WhisperMailboxSuite) requestHistoricMessages(w *whisper.Whisper, rpcCli *rpc.Client, mailboxEnode, mailServerKeyID, topic string, from, to time.Time) []byte {
|
||||||
resp := rpcCli.CallRaw(`{
|
resp := rpcCli.CallRaw(`{
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"id": 2,
|
"id": 2,
|
||||||
|
|
Loading…
Reference in New Issue