mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-15 16:42:38 +08:00
fix: DeleteDoc crash
This commit is contained in:
parent
a060da5ec6
commit
f60272a1d2
4
go.mod
4
go.mod
@ -219,3 +219,7 @@ require (
|
|||||||
golang.org/x/crypto v0.27.0 // indirect
|
golang.org/x/crypto v0.27.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace (
|
||||||
|
github.com/openimsdk/tools => /Users/chao/Desktop/code/tools
|
||||||
|
)
|
@ -223,15 +223,19 @@ func (ws *WsServer) sendUserOnlineInfoToOtherNode(ctx context.Context, client *C
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if len(conns) == 0 || (len(conns) == 1 && ws.disCov.IsSelfNode(conns[0])) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
wg := errgroup.Group{}
|
wg := errgroup.Group{}
|
||||||
wg.SetLimit(concurrentRequest)
|
wg.SetLimit(concurrentRequest)
|
||||||
|
|
||||||
// Online push user online message to other node
|
// Online push user online message to other node
|
||||||
for _, v := range conns {
|
for _, v := range conns {
|
||||||
v := v
|
v := v
|
||||||
log.ZDebug(ctx, " sendUserOnlineInfoToOtherNode conn ", "target", v.Target())
|
log.ZDebug(ctx, "sendUserOnlineInfoToOtherNode conn")
|
||||||
if v.Target() == ws.disCov.GetSelfConnTarget() {
|
if ws.disCov.IsSelfNode(v) {
|
||||||
log.ZDebug(ctx, "Filter out this node", "node", v.Target())
|
log.ZDebug(ctx, "Filter out this node")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,7 +246,7 @@ func (ws *WsServer) sendUserOnlineInfoToOtherNode(ctx context.Context, client *C
|
|||||||
PlatformID: int32(client.PlatformID), Token: client.token,
|
PlatformID: int32(client.PlatformID), Token: client.token,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZWarn(ctx, "MultiTerminalLoginCheck err", err, "node", v.Target())
|
log.ZWarn(ctx, "MultiTerminalLoginCheck err", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -166,7 +166,7 @@ func (k *K8sStaticConsistentHash) GetConnsAndOnlinePush(ctx context.Context, msg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.ZDebug(ctx, "genUsers send hosts struct:", "usersHost", usersHost)
|
log.ZDebug(ctx, "genUsers send hosts struct:", "usersHost", usersHost)
|
||||||
var usersConns = make(map[*grpc.ClientConn][]string)
|
var usersConns = make(map[grpc.ClientConnInterface][]string)
|
||||||
for host, userIds := range usersHost {
|
for host, userIds := range usersHost {
|
||||||
tconn, _ := k.disCov.GetConn(ctx, host)
|
tconn, _ := k.disCov.GetConn(ctx, host)
|
||||||
usersConns[tconn] = userIds
|
usersConns[tconn] = userIds
|
||||||
|
@ -192,7 +192,7 @@ func (s *authServer) forceKickOff(ctx context.Context, userID string, platformID
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, v := range conns {
|
for _, v := range conns {
|
||||||
log.ZDebug(ctx, "forceKickOff", "conn", v.Target())
|
log.ZDebug(ctx, "forceKickOff", "userID", userID, "platformID", platformID)
|
||||||
client := msggateway.NewMsgGatewayClient(v)
|
client := msggateway.NewMsgGatewayClient(v)
|
||||||
kickReq := &msggateway.KickUserOfflineReq{KickUserIDList: []string{userID}, PlatformID: platformID}
|
kickReq := &msggateway.KickUserOfflineReq{KickUserIDList: []string{userID}, PlatformID: platformID}
|
||||||
_, err := client.KickUserOffline(ctx, kickReq)
|
_, err := client.KickUserOffline(ctx, kickReq)
|
||||||
|
@ -1,56 +1,134 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"context"
|
||||||
"net"
|
"fmt"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
"github.com/openimsdk/protocol/group"
|
||||||
|
"github.com/openimsdk/protocol/user"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ user.UnimplementedUserServer
|
||||||
|
_ group.UnimplementedGroupServer
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestName1(t *testing.T) {
|
func TestName1(t *testing.T) {
|
||||||
|
cc := newStandaloneConn()
|
||||||
tls.Client(&testConn{}, &tls.Config{}).Handshake()
|
user.RegisterUserServer(cc.Registry(), &user.UnimplementedUserServer{})
|
||||||
|
group.RegisterGroupServer(cc.Registry(), &group.UnimplementedGroupServer{})
|
||||||
time.Sleep(time.Hour)
|
ctx := context.Background()
|
||||||
|
resp, err := user.NewUserClient(cc).GetUserStatus(ctx, &user.GetUserStatusReq{UserID: "imAdmin", UserIDs: []string{"10000", "20000"}})
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Log(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
type testConn struct {
|
func newStandaloneConn() *standaloneConn {
|
||||||
|
return &standaloneConn{
|
||||||
|
registry: newStandaloneRegistry(),
|
||||||
|
serializer: NewProtoSerializer(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testConn) Read(b []byte) (n int, err error) {
|
type standaloneConn struct {
|
||||||
panic("implement me")
|
registry *standaloneRegistry
|
||||||
|
serializer Serializer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testConn) Write(b []byte) (n int, err error) {
|
func (x *standaloneConn) Registry() grpc.ServiceRegistrar {
|
||||||
panic("implement me")
|
return x.registry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testConn) Close() error {
|
func (x *standaloneConn) Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error {
|
||||||
//TODO implement me
|
handler := x.registry.getMethod(method)
|
||||||
panic("implement me")
|
if handler == nil {
|
||||||
|
return fmt.Errorf("service %s not found", method)
|
||||||
|
}
|
||||||
|
resp, err := handler(ctx, args, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tmp, err := x.serializer.Marshal(resp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return x.serializer.Unmarshal(tmp, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testConn) LocalAddr() net.Addr {
|
func (x *standaloneConn) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) {
|
||||||
//TODO implement me
|
return nil, status.Errorf(codes.Unimplemented, "method stream not implemented")
|
||||||
panic("implement me")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testConn) RemoteAddr() net.Addr {
|
type serverHandler func(ctx context.Context, req any, interceptor grpc.UnaryServerInterceptor) (any, error)
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
func newStandaloneRegistry() *standaloneRegistry {
|
||||||
|
return &standaloneRegistry{
|
||||||
|
methods: make(map[string]serverHandler),
|
||||||
|
serializer: NewProtoSerializer(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testConn) SetDeadline(t time.Time) error {
|
type standaloneRegistry struct {
|
||||||
//TODO implement me
|
lock sync.RWMutex
|
||||||
panic("implement me")
|
methods map[string]serverHandler
|
||||||
|
serializer Serializer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testConn) SetReadDeadline(t time.Time) error {
|
func (x *standaloneConn) emptyDec(req any) error {
|
||||||
//TODO implement me
|
return nil
|
||||||
panic("implement me")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testConn) SetWriteDeadline(t time.Time) error {
|
func (x *standaloneRegistry) RegisterService(desc *grpc.ServiceDesc, impl any) {
|
||||||
//TODO implement me
|
x.lock.Lock()
|
||||||
panic("implement me")
|
defer x.lock.Unlock()
|
||||||
|
for i := range desc.Methods {
|
||||||
|
method := desc.Methods[i]
|
||||||
|
name := fmt.Sprintf("/%s/%s", desc.ServiceName, method.MethodName)
|
||||||
|
if _, ok := x.methods[name]; ok {
|
||||||
|
panic(fmt.Errorf("service %s already registered, method %s", desc.ServiceName, method.MethodName))
|
||||||
|
}
|
||||||
|
x.methods[name] = func(ctx context.Context, req any, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||||
|
return method.Handler(impl, ctx, func(in any) error {
|
||||||
|
tmp, err := x.serializer.Marshal(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return x.serializer.Unmarshal(tmp, in)
|
||||||
|
}, interceptor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *standaloneRegistry) getMethod(name string) serverHandler {
|
||||||
|
x.lock.RLock()
|
||||||
|
defer x.lock.RUnlock()
|
||||||
|
return x.methods[name]
|
||||||
|
}
|
||||||
|
|
||||||
|
type Serializer interface {
|
||||||
|
Marshal(any) ([]byte, error)
|
||||||
|
Unmarshal([]byte, any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewProtoSerializer() Serializer {
|
||||||
|
return protoSerializer{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type protoSerializer struct{}
|
||||||
|
|
||||||
|
func (protoSerializer) Marshal(in any) ([]byte, error) {
|
||||||
|
return proto.Marshal(in.(proto.Message))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (protoSerializer) Unmarshal(b []byte, out any) error {
|
||||||
|
return proto.Unmarshal(b, out.(proto.Message))
|
||||||
}
|
}
|
||||||
|
@ -1,67 +1,34 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
//
|
||||||
"context"
|
//import (
|
||||||
"fmt"
|
// "context"
|
||||||
|
// "fmt"
|
||||||
"google.golang.org/grpc"
|
// "sync"
|
||||||
)
|
//
|
||||||
|
// "google.golang.org/grpc"
|
||||||
type Conn interface {
|
//)
|
||||||
GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]grpc.ClientConnInterface, error) //1
|
//
|
||||||
GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (grpc.ClientConnInterface, error) //2
|
//type DiscoveryRegistry struct {
|
||||||
GetSelfConnTarget() string //3
|
// lock sync.RWMutex
|
||||||
AddOption(opts ...grpc.DialOption) //4
|
// services map[string]grpc.ClientConnInterface
|
||||||
CloseConn(conn *grpc.ClientConn) //5
|
//}
|
||||||
// do not use this method for call rpc
|
//
|
||||||
}
|
//func (x *DiscoveryRegistry) RegisterService(desc *grpc.ServiceDesc, impl any) {
|
||||||
type SvcDiscoveryRegistry interface {
|
// fmt.Println("RegisterService", desc, impl)
|
||||||
Conn
|
//}
|
||||||
Register(serviceName, host string, port int, opts ...grpc.DialOption) error //6
|
//
|
||||||
UnRegister() error //7
|
//func (x *DiscoveryRegistry) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]grpc.ClientConnInterface, error) {
|
||||||
Close()
|
// //TODO implement me
|
||||||
GetUserIdHashGatewayHost(ctx context.Context, userId string) (string, error) //
|
// panic("implement me")
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
var _ SvcDiscoveryRegistry = (*DiscoveryRegistry)(nil)
|
//func (x *DiscoveryRegistry) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (grpc.ClientConnInterface, error) {
|
||||||
|
// //TODO implement me
|
||||||
type DiscoveryRegistry struct {
|
// panic("implement me")
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func (x *DiscoveryRegistry) RegisterService(desc *grpc.ServiceDesc, impl any) {
|
//func (x *DiscoveryRegistry) IsSelfNode(cc grpc.ClientConnInterface) bool {
|
||||||
fmt.Println("RegisterService", desc, impl)
|
//
|
||||||
}
|
// return false
|
||||||
|
//}
|
||||||
func (x *DiscoveryRegistry) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]grpc.ClientConnInterface, error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *DiscoveryRegistry) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (grpc.ClientConnInterface, error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *DiscoveryRegistry) GetSelfConnTarget() string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *DiscoveryRegistry) AddOption(opts ...grpc.DialOption) {}
|
|
||||||
|
|
||||||
func (x *DiscoveryRegistry) CloseConn(conn *grpc.ClientConn) {
|
|
||||||
_ = conn.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *DiscoveryRegistry) Register(serviceName, host string, port int, opts ...grpc.DialOption) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *DiscoveryRegistry) UnRegister() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *DiscoveryRegistry) Close() {}
|
|
||||||
|
|
||||||
func (x *DiscoveryRegistry) GetUserIdHashGatewayHost(ctx context.Context, userId string) (string, error) {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user