Skip to content

Port.Write() returns nil error after partial write; does not adhere to the io.Writer contract #191

Open
@ccollins476ad

Description

@ccollins476ad

Describe the problem

(see #192)

From the io.Writer GoDoc:

Write must return a non-nil error if it returns n < len(p).

The docs (doc.go) indicate that serial.Port implements the io.Writer interface:

The port object implements the io.ReadWriteCloser interface, so we can use
the usual Read, Write and Close functions to send and receive data from the
serial port...

However, I have seen instances where serial.Port.Write() reports success after a partial write. It seems the unix implementation forwards the data to the write syscall, but the syscall does not provide the same guarantee as io.Writer.

To reproduce

It varies by hardware/driver, but the steps would just be to open a port and write lots of data.

Please double-check that you have reported each of the following

before submitting the issue.

  • I've provided the FULL source code that causes the problem
  • I've provided all the actions required to reproduce the problem

Expected behavior

Write() should either write the entire buffer and return err=nil, or it should return an error.

Operating system and version

Linux, seen on multiple versions

Please describe your hardware setup

No response

Additional context

No response

Issue checklist

  • I searched for previous requests in the issue tracker
  • My request contains all necessary details

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions