簡體   English   中英

rpc sendResponse panic:reflect:在ptr上調用reflect.Value.Int

[英]rpc sendResponse panic:reflect: call of reflect.Value.Int on ptr

我的服務器在前一天出現緊急情況時,在生產環境中運行良好。

我在圍棋論壇上發布了一個問題,有人告訴我進行種族檢測。

我看到net / rpc。(* Server).sendResponse是線程安全的。

rpc包中的sendResponse有什么問題嗎?

在我的代碼中,reply只是一個* int,並且在功能上沒有任何作用,因此我不知道這種恐慌:

panic: reflect: call of reflect.Value.Int on ptr Value [recovered]  
panic: reflect: call of reflect.Value.Int on ptr Value  
goroutine 52598456 [running]:  
encoding/gob.catchError(0xc4209e10d0) 
/root/go/src/encoding/gob/error.go:38 +0x95  
    panic(0xc40860, 0xc42606ad00) 
/root/go/src/runtime/panic.go:489 +0x2cf  
    reflect.Value.Int(0xbcdec0, 0xc4251fe520, 0x196, 0x196)  
/root/go/src/reflect/value.go:902 +0xb5  
    encoding/gob.encInt(0xc423ab4ae0, 0xc422da1e40, 0xbcdec0, 0xc4251fe520, 0x196)  
/root/go/src/encoding/gob/encode.go:188 +0x43  
    encoding/gob.(*Encoder).encodeStruct(0xc4209e1040, 0xc4209e1078, 0xc421a28a20, 0xcc1be0, 0xc4251fe510, 0x199)  
/root/go/src/encoding/gob/encode.go:334 +0x256  
    encoding/gob.(*Encoder).encode(0xc4209e1040, 0xc4209e1078, 0xcc1be0, 0xc4251fe510, 0x199, 0xc4209c3480)  
/root/go/src/encoding/gob/encode.go:707 +0x1d3
    encoding/gob.(*Encoder).EncodeValue(0xc4209e1040, 0xc95bc0, 0xc4251fe510, 0x16, 0x0, 0x0)  
/root/go/src/encoding/gob/encoder.go:250 +0x3ab  
    encoding/gob.(*Encoder).Encode(0xc4209e1040, 0xc95bc0, 0xc4251fe510, 0x0, 0x0) 
/root/go/src/encoding/gob/encoder.go:175 +0x61  
    net/rpc.(*gobServerCodec).WriteResponse(0xc422b51ec0, 0xc422d737d0, 0xc95bc0, 0xc4251fe510, 0xc422b43a40, 0xc422b4a350)  
/root/go/src/net/rpc/server.go:424 +0x1dd  
    net/rpc.(*Server).sendResponse(0xc420055680, 0xc422b45aa0, 0xc421c4ff00, 0xc95bc0, 0xc4251fe510, 0x1334ac0, 0xc422b51ec0, 0x0, 0x0)  
/root/go/src/net/rpc/server.go:366 +0x130  
    net/rpc.(*service).call(0xc422afe900, 0xc420055680, 0xc422b45aa0, 0xc422b4ec00, 0xc421c4ff00, 0xbc3800, 0xc427ab07e0, 0x16, 0xc95bc0, 0xc4251fe510, ...)  
/root/go/src/net/rpc/server.go:394 +0x22e  
    created by net/rpc.(*Server).ServeCodec  
/root/go/src/net/rpc/server.go:481 +0x404     

type RpcArgs struct{ A string B int32 C string D int32 E String F int32 G int32 H int32 I bool J string K int32 L String M int32 N int32 O int32 P bool }

func RPC1(args *RpcArgs, reply *int) error{ //some simple logic with args, do noting with reply //do another async rpc call,may be this is useless var reply2 int rpc.Client.Go(serviceMethod, args, &reply2, make(chan *rpc.Call, 1)) return nil }

就像that.reply * int這樣的源代碼直接返回,在RPC1中未修改

我認為net/rpc包中的sendResponse函數沒有問題。

當遇到遇到nil指針時,Encode函數中的請求會出現緊急情況。 您應該閱讀gob/encodeStruct上的文檔,以了解在什么情況下無法對值進行編碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM