diff --git a/virtcontainers/fc.go b/virtcontainers/fc.go index bdb8753e7..9293984a9 100644 --- a/virtcontainers/fc.go +++ b/virtcontainers/fc.go @@ -180,6 +180,19 @@ func (fc *firecracker) trace(name string) (opentracing.Span, context.Context) { return span, ctx } +//At some cases, when sandbox id is too long, it will incur error of overlong +//firecracker API unix socket(fc.socketPath). +//In Linux, sun_path could maximumly contains 108 bytes in size. +//(http://man7.org/linux/man-pages/man7/unix.7.html) +func (fc *firecracker) truncateID(id string) string { + if len(id) > 32 { + //truncate the id to only leave the size of UUID(128bit). + return id[:32] + } + + return id +} + // For firecracker this call only sets the internal structure up. // The sandbox will be created and started through startSandbox(). func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, stateful bool) error { @@ -190,7 +203,7 @@ func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS N //TODO: check validity of the hypervisor config provided //https://github.com/kata-containers/runtime/issues/1065 - fc.id = id + fc.id = fc.truncateID(id) fc.state.set(notReady) fc.config = *hypervisorConfig fc.stateful = stateful diff --git a/virtcontainers/fc_test.go b/virtcontainers/fc_test.go index badcf7980..b1e43632f 100644 --- a/virtcontainers/fc_test.go +++ b/virtcontainers/fc_test.go @@ -29,3 +29,19 @@ func TestFCGenerateSocket(t *testing.T) { assert.NotEmpty(hvsock.UdsPath) assert.NotZero(hvsock.Port) } + +func TestFCTruncateID(t *testing.T) { + assert := assert.New(t) + + fc := firecracker{} + + testLongID := "3ef98eb7c6416be11e0accfed2f4e6560e07f8e33fa8d31922fd4d61747d7ead" + expectedID := "3ef98eb7c6416be11e0accfed2f4e656" + id := fc.truncateID(testLongID) + assert.Equal(expectedID, id) + + testShortID := "3ef98eb7c6416be11" + expectedID = "3ef98eb7c6416be11" + id = fc.truncateID(testShortID) + assert.Equal(expectedID, id) +}