Skip to content

panic: runtime error with 32 bits CPU Arquitectures  #755

@dumacp

Description

@dumacp

Describe the bug

This code:

func (s *SliceMap) GetBucket(key string) cmap.ConcurrentMap {
	hash := murmur32.Sum32([]byte(key))
	index := int(hash) % len(s.LocalPIDs)

	return s.LocalPIDs[index]
}

in https://github.com/asynkron/protoactor-go/blob/dev/actor/process_registry.go

cuases a panic: runtime error: index out of range [-327] when the code is compiled for 32 bit architecture

To Reproduce

Run the next code in 32 bit arquitecture

package main

import (
        "time"

        "github.com/asynkron/protoactor-go/actor"
        "github.com/asynkron/protoactor-go/remote"
)

func main() {
        sys := actor.NewActorSystem()

        rconfig := remote.Configure("127.0.0.1", 8910)
        r := remote.NewRemote(sys, rconfig)
        r.Start()
        time.Sleep(30 * time.Second)
}

The instruction hash := murmur32.Sum32([]byte(key)) in the function func (s *SliceMap) GetBucket(key string) cmap.ConcurrentMap returns a uint32, the conversion int(hash) in 32 bit arquitecture could return a negative number, and a panic in s.LocalPIDs[index] when the index is negative.

panic: runtime error: index out of range [-327]

goroutine 1 [running]:
github.com/asynkron/protoactor-go/actor.(*SliceMap).GetBucket(0x149fbb0, {0x141a0f0, 0xa})
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/actor/process_registry.go:38 +0xd0
github.com/asynkron/protoactor-go/actor.(*ProcessRegistryValue).Add(0x1922000, {0x6dc6a8, 0x140e110}, {0x141a0f0, 0xa})
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/actor/process_registry.go:89 +0x30
github.com/asynkron/protoactor-go/actor.(*guardiansValue).newGuardian(0x1410040, {0x6da25c, 0xa5c8a0})
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/actor/guardian.go:39 +0x114
github.com/asynkron/protoactor-go/actor.(*guardiansValue).getGuardianPid(0x1410040, {0x6da25c, 0xa5c8a0})
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/actor/guardian.go:26 +0x8c
github.com/asynkron/protoactor-go/actor.(*RootContext).Self(0x19240f0)
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/actor/root_context.go:81 +0x3c
github.com/asynkron/protoactor-go/actor.glob..func1(0x1480d50, {0x6122aa, 0x9}, 0x193c000, {0x6deb00, 0x19240f0})
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/actor/props.go:27 +0x28
github.com/asynkron/protoactor-go/actor.(*Props).spawn(0x193c000, 0x1480d50, {0x6122aa, 0x9}, {0x6deb00, 0x19240f0})
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/actor/props.go:144 +0x60
github.com/asynkron/protoactor-go/actor.(*RootContext).SpawnNamed(0x1924000, 0x193c000, {0x6122aa, 0x9})
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/actor/root_context.go:186 +0x134
github.com/asynkron/protoactor-go/remote.(*endpointManager).startActivator(0x1920920)
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/remote/endpoint_manager.go:128 +0xec
github.com/asynkron/protoactor-go/remote.(*endpointManager).start(0x1920920)
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/remote/endpoint_manager.go:85 +0xc4
github.com/asynkron/protoactor-go/remote.(*Remote).Start(0x1920900)
	/home/duma/go/pkg/mod/github.com/asynkron/protoactor-go@v0.0.0-20221002142108-880b460fcd1f/remote/server.go:79 +0x4f8
main.main()
	/tests/main_bugprotocator/main.go:15 +0x9c

Expected behavior
avoid conversion int32 from uint32 when the return is negative.

Additional context
The problem is in 32 bit Arquitecture because the built-in type int is a 32 bit data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions