Bug 292322 - Hastd failing to g_attach device on FreeBSD 15.0
Summary: Hastd failing to g_attach device on FreeBSD 15.0
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 15.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Dag-Erling Smørgrav
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-01-10 08:00 UTC by Alessandro Sagratini
Modified: 2026-10-14 16:25 UTC (History)
2 users (show)

See Also:
des: mfc-stable15+
des: mfc-stable14+


Attachments
hast.conf (182 bytes, text/plain)
2026-01-10 08:00 UTC, Alessandro Sagratini
no flags Details
gpart show and hastctl dump all output (1.78 KB, text/plain)
2026-01-10 08:01 UTC, Alessandro Sagratini
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alessandro Sagratini 2026-01-10 08:00:19 UTC
Created attachment 266984 [details]
hast.conf

Hi all, 
I am trying to set up hastd on FreeBSD 15.0-RELEASE, but I keep getting errors like

[58519] g_dev_taste: g_dev_taste(hast/shared) failed to g_attach, error=6

/var/log/messages:{"time":"20260104190514","host":"nattaneo","facility":"[kern.notice]","msg":"kernel: : [1104] g_dev_taste: g_dev_taste(hast/shared) failed to g_attach, error=6"
/var/log/messages:{"time":"20260105063137","host":"nattaneo","facility":"[syslog.err]","msg":"syslog-ng[26434]: Error processing log message: <30>1 2026-01-05T06:31:37.242261+00:00 >@<hastd: shared (primary) hastd 61114 - - [shared] (primary) Privileges successfully dropped."

on the primary node and

{"time":"20260110074150","host":"nodeb","facility":"[daemon.err]","msg":"hastd[45686]: Unable to receive header from tcp://10.255.255.1:18765: Operation timed out."

on the secondary one. I create the device as explained in the handbook:

hastctl create shared
service hastd start
hastctl role primary shared

on the primary node and 

hastctl create shared
service hastd start
hastctl role secondary shared

on the secondary. There are no firewall rules that might cause connection issues:
[ale@hosta ~]$ nc -vz 10.255.255.2 8457
Connection to 10.255.255.2 8457 port [tcp/*] succeeded!

[ale@hostb ~]$ nc -vz 10.255.255.1 8457
Connection to 10.255.255.1 8457 port [tcp/*] succeeded!

For what it's worth, the root filesystem is ZFS, but the configuration is identical on both hosts (hast.conf file is attached) an d I am also attaching the output of gpart show and hastctl dump all.

Anything that might be causing this since the same configuration used to work as expected on 14.3-RELEASE?

Let me know if you need anything else, thank you
Comment 1 Alessandro Sagratini 2026-01-10 08:01:14 UTC
Created attachment 266985 [details]
gpart show and hastctl dump all output
Comment 2 Martin Vidovic 2026-06-10 20:56:18 UTC
I've hit this exact problem when setting up HAST on FreeBSD 15.0 and decided to investigate, here is the summary:

The timeout on the secondary node ("Unable to receive header") was traced to the parent/worker connection migration path in hastd (on primary) rather than the replication protocol itself.

The connection migration code transfers a protocol name and a connected socket descriptor over a local AF_UNIX socketpair. The protocol name is sent using send(2), while the descriptor is sent separately using sendmsg(2) with SCM_RIGHTS.

The receive side calls recv(2) with a buffer sized for the maximum protocol name length and uses MSG_WAITALL. On FreeBSD 15.0 this causes the receiver to wait indefinitely for the full buffer size rather than returning after receiving the protocol name. Because of this the primary never sends the HAST header and the resource doesn't appear in /dev/hast/.

A review has been submitted with a patch that sends the protocol name and descriptor together using a single sendmsg()/recvmsg() exchange.

With the patch applied, the primary successfully creates /dev/hast/, the secondary receives the HAST protocol header, and synchronization completes successfully.
Comment 3 Alessandro Sagratini 2026-06-11 06:58:13 UTC
Hi Martin,
thanks a lot for the detailed summary! Is https://reviews.freebsd.org/D57511 the proposed change you mentioned?

Let's see how that works out, thank you
Comment 4 Alessandro Sagratini 2026-06-11 06:58:35 UTC
Hi Martin,
thanks a lot for the detailed summary! Is https://reviews.freebsd.org/D57511 the proposed change you mentioned?

Let's see how that works out, thank you
Comment 5 Martin Vidovic 2026-06-11 10:09:03 UTC
(In reply to Alessandro Sagratini from comment #3)
Hi Alessandro, that's right.
Comment 6 Alessandro Sagratini 2026-06-11 15:19:57 UTC
perfect, hopefully this issue will be fixed as soon as possible, thank you!
Comment 7 Glen Barber freebsd_committer freebsd_triage 2026-08-29 19:38:14 UTC
I independently reproduced this exact issue while testing HAST for a project (two FreeBSD 15.1-RELEASE VMs).

Same symptom: primary stuck at degraded, secondary logging Unable to receive header from tcp://...: Operation timed out., and the same g_dev_taste ... failed to g_attach, error=6 kernel message.

Diagnostic detail that may help confirm the root cause: a packet capture during a role primary attempt shows a completely clean TCP three-way handshake followed by ~20 seconds of total silence in both directions before the connection times out — confirming the network layer is healthy and the primary genuinely never transmits anything. 'procstat -t' on the primary's worker process shows kernel threads parked in sbwait with no forward progress, and 'truss -H' confirms zero connect/send/recv syscalls occur — consistent with Martin's diagnosis of the worker blocking on recv(2)/MSG_WAITALL in the connection-migration path.

I also confirmed this is not 15-specific: pairing a FreeBSD 16.0-CURRENT node (main-n288684-420428718da7) with a 15.1-RELEASE node reproduces the identical failure, so the affected code path is still present in HEAD as of 2026-08-29.
Comment 8 Glen Barber freebsd_committer freebsd_triage 2026-08-29 21:47:41 UTC
Follow-up to my earlier reproduction report: I built hastd from a source tree with D57511 applied and tested it directly.

Setup: two FreeBSD nodes, one running the patched hastd (built from a source checkout with D57511 applied — no other changes) acting as primary, the other running stock unpatched hastd as secondary. Same resource config as before.

Result: hastctl list reports status: complete on both sides — previously it stuck at degraded indefinitely on the same setup with an unpatched primary. I also verified actual data replication, not just the status flag: writing through /dev/hast/<resource> on the primary showed the resource's dirty counter go from 0 to the extent size and back to 0 after the write, confirming the data was really synced to the secondary and the sync tracking cleared normally.

One detail that may be useful: only the primary side needed the patch — the secondary ran unpatched hastd throughout and worked fine, consistent with the bug being entirely in the primary's own connection-migration path. That said, since any node can become primary in practice, patching all nodes is still the right move once this lands.

This confirms the fix works completely, on top of the 16.0-CURRENT confirmation from my last comment. Thanks again to Martin for the diagnosis — hope this helps get D57511 through review.
Comment 9 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2026-09-16 15:48:13 UTC

*** This bug has been marked as a duplicate of bug 234576 ***
Comment 10 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2026-09-16 15:50:07 UTC
Oops, not a duplicate
Comment 11 commit-hook freebsd_committer freebsd_triage 2026-09-20 17:07:45 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=cd8eef45d2d0296afe0226bde587f52eb0404516

commit cd8eef45d2d0296afe0226bde587f52eb0404516
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-09-08 20:55:15 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-09-20 16:51:12 +0000

    hastd: Use fixed-length protocol names

    All communication between hastd nodes and internally between hastd and
    its worker children passes through the same pair of send / receive
    functions.  The receive function uses recv(2) with the MSG_WAITALL flag,
    which in theory means we should never get a short read.  However, when
    handing off a socket to a worker child, we also pass a variable-length
    string identifying the type of socket we're passing, and reading this
    string relies on a short read.  This used to work because the arrival of
    the descriptor would interrupt the recv(2) call, but this bug was fixed
    when the AF_UNIX code was rewritten a while ago and hastd has been
    broken ever since.

    Fixing the length of the protocol name to four characters including the
    terminating null solves the short-read bug by never requiring a short
    read (nothing else in hastd requires one).

    Note that this issue appears to have been reported independently first
    by Alessandro Sagratini in PR 292322 and then by Martin Vidovic in
    D57511.  I ended up going in a different direction than Martin's patch,
    but his analysis was invaluable, hence the double credit below.

    PR:             292322
    Reported by:    Martin Vidovic <xtronom@gmail.com>
    MFC after:      1 week
    Event:          EuroBSDcon DevSummit 2026
    Reviewed by:    xtronom_gmail.com, kevans, glebius, gjb
    Differential Revision:  https://reviews.freebsd.org/D59521

    (cherry picked from commit b7e5c2e008f5b441611830ad3a0329de0882419e)

 sbin/hastd/proto.c            | 15 +++++----------
 sbin/hastd/proto_impl.h       |  2 +-
 sbin/hastd/proto_socketpair.c |  2 +-
 3 files changed, 7 insertions(+), 12 deletions(-)
Comment 12 commit-hook freebsd_committer freebsd_triage 2026-09-20 17:08:47 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=9401bfb06108e49cc125a237469886da34bb4f38

commit 9401bfb06108e49cc125a237469886da34bb4f38
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-09-08 20:55:15 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-09-20 16:51:17 +0000

    hastd: Use fixed-length protocol names

    All communication between hastd nodes and internally between hastd and
    its worker children passes through the same pair of send / receive
    functions.  The receive function uses recv(2) with the MSG_WAITALL flag,
    which in theory means we should never get a short read.  However, when
    handing off a socket to a worker child, we also pass a variable-length
    string identifying the type of socket we're passing, and reading this
    string relies on a short read.  This used to work because the arrival of
    the descriptor would interrupt the recv(2) call, but this bug was fixed
    when the AF_UNIX code was rewritten a while ago and hastd has been
    broken ever since.

    Fixing the length of the protocol name to four characters including the
    terminating null solves the short-read bug by never requiring a short
    read (nothing else in hastd requires one).

    Note that this issue appears to have been reported independently first
    by Alessandro Sagratini in PR 292322 and then by Martin Vidovic in
    D57511.  I ended up going in a different direction than Martin's patch,
    but his analysis was invaluable, hence the double credit below.

    PR:             292322
    Reported by:    Martin Vidovic <xtronom@gmail.com>
    MFC after:      1 week
    Event:          EuroBSDcon DevSummit 2026
    Reviewed by:    xtronom_gmail.com, kevans, glebius, gjb
    Differential Revision:  https://reviews.freebsd.org/D59521

    (cherry picked from commit b7e5c2e008f5b441611830ad3a0329de0882419e)

 sbin/hastd/proto.c            | 15 +++++----------
 sbin/hastd/proto_impl.h       |  2 +-
 sbin/hastd/proto_socketpair.c |  2 +-
 3 files changed, 7 insertions(+), 12 deletions(-)
Comment 13 commit-hook freebsd_committer freebsd_triage 2026-10-14 16:04:03 UTC
A commit in branch releng/14.4 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1c821dc49b536cf2d925487324e0785a7a1400c6

commit 1c821dc49b536cf2d925487324e0785a7a1400c6
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-09-08 20:55:15 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-10-13 13:47:11 +0000

    hastd: Use fixed-length protocol names

    All communication between hastd nodes and internally between hastd and
    its worker children passes through the same pair of send / receive
    functions.  The receive function uses recv(2) with the MSG_WAITALL flag,
    which in theory means we should never get a short read.  However, when
    handing off a socket to a worker child, we also pass a variable-length
    string identifying the type of socket we're passing, and reading this
    string relies on a short read.  This used to work because the arrival of
    the descriptor would interrupt the recv(2) call, but this bug was fixed
    when the AF_UNIX code was rewritten a while ago and hastd has been
    broken ever since.

    Fixing the length of the protocol name to four characters including the
    terminating null solves the short-read bug by never requiring a short
    read (nothing else in hastd requires one).

    Note that this issue appears to have been reported independently first
    by Alessandro Sagratini in PR 292322 and then by Martin Vidovic in
    D57511.  I ended up going in a different direction than Martin's patch,
    but his analysis was invaluable, hence the double credit below.

    Approved by:    so
    Security:       FreeBSD-EN-26:26.hastd
    PR:             292322
    Reported by:    Martin Vidovic <xtronom@gmail.com>
    MFC after:      1 week
    Event:          EuroBSDcon DevSummit 2026
    Reviewed by:    xtronom_gmail.com, kevans, glebius, gjb
    Differential Revision:  https://reviews.freebsd.org/D59521

    (cherry picked from commit b7e5c2e008f5b441611830ad3a0329de0882419e)
    (cherry picked from commit 9401bfb06108e49cc125a237469886da34bb4f38)

 sbin/hastd/proto.c            | 15 +++++----------
 sbin/hastd/proto_impl.h       |  2 +-
 sbin/hastd/proto_socketpair.c |  2 +-
 3 files changed, 7 insertions(+), 12 deletions(-)
Comment 14 commit-hook freebsd_committer freebsd_triage 2026-10-14 16:05:05 UTC
A commit in branch releng/14.5 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=49baaf01c26af6a35a585bcf73e0009c2fd37ad6

commit 49baaf01c26af6a35a585bcf73e0009c2fd37ad6
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-09-08 20:55:15 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-10-13 14:03:00 +0000

    hastd: Use fixed-length protocol names

    All communication between hastd nodes and internally between hastd and
    its worker children passes through the same pair of send / receive
    functions.  The receive function uses recv(2) with the MSG_WAITALL flag,
    which in theory means we should never get a short read.  However, when
    handing off a socket to a worker child, we also pass a variable-length
    string identifying the type of socket we're passing, and reading this
    string relies on a short read.  This used to work because the arrival of
    the descriptor would interrupt the recv(2) call, but this bug was fixed
    when the AF_UNIX code was rewritten a while ago and hastd has been
    broken ever since.

    Fixing the length of the protocol name to four characters including the
    terminating null solves the short-read bug by never requiring a short
    read (nothing else in hastd requires one).

    Note that this issue appears to have been reported independently first
    by Alessandro Sagratini in PR 292322 and then by Martin Vidovic in
    D57511.  I ended up going in a different direction than Martin's patch,
    but his analysis was invaluable, hence the double credit below.

    Approved by:    so
    Security:       FreeBSD-EN-26:26.hastd
    PR:             292322
    Reported by:    Martin Vidovic <xtronom@gmail.com>
    MFC after:      1 week
    Event:          EuroBSDcon DevSummit 2026
    Reviewed by:    xtronom_gmail.com, kevans, glebius, gjb
    Differential Revision:  https://reviews.freebsd.org/D59521

    (cherry picked from commit b7e5c2e008f5b441611830ad3a0329de0882419e)
    (cherry picked from commit 9401bfb06108e49cc125a237469886da34bb4f38)

 sbin/hastd/proto.c            | 15 +++++----------
 sbin/hastd/proto_impl.h       |  2 +-
 sbin/hastd/proto_socketpair.c |  2 +-
 3 files changed, 7 insertions(+), 12 deletions(-)
Comment 15 commit-hook freebsd_committer freebsd_triage 2026-10-14 16:05:08 UTC
A commit in branch releng/15.1 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=c8fe55b4726ae56ceaa6d0828403780dcef72c54

commit c8fe55b4726ae56ceaa6d0828403780dcef72c54
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-09-08 20:55:15 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-10-13 14:10:21 +0000

    hastd: Use fixed-length protocol names

    All communication between hastd nodes and internally between hastd and
    its worker children passes through the same pair of send / receive
    functions.  The receive function uses recv(2) with the MSG_WAITALL flag,
    which in theory means we should never get a short read.  However, when
    handing off a socket to a worker child, we also pass a variable-length
    string identifying the type of socket we're passing, and reading this
    string relies on a short read.  This used to work because the arrival of
    the descriptor would interrupt the recv(2) call, but this bug was fixed
    when the AF_UNIX code was rewritten a while ago and hastd has been
    broken ever since.

    Fixing the length of the protocol name to four characters including the
    terminating null solves the short-read bug by never requiring a short
    read (nothing else in hastd requires one).

    Note that this issue appears to have been reported independently first
    by Alessandro Sagratini in PR 292322 and then by Martin Vidovic in
    D57511.  I ended up going in a different direction than Martin's patch,
    but his analysis was invaluable, hence the double credit below.

    Approved by:    so
    Security:       FreeBSD-EN-26:26.hastd
    PR:             292322
    Reported by:    Martin Vidovic <xtronom@gmail.com>
    MFC after:      1 week
    Event:          EuroBSDcon DevSummit 2026
    Reviewed by:    xtronom_gmail.com, kevans, glebius, gjb
    Differential Revision:  https://reviews.freebsd.org/D59521

    (cherry picked from commit b7e5c2e008f5b441611830ad3a0329de0882419e)
    (cherry picked from commit cd8eef45d2d0296afe0226bde587f52eb0404516)

 sbin/hastd/proto.c            | 15 +++++----------
 sbin/hastd/proto_impl.h       |  2 +-
 sbin/hastd/proto_socketpair.c |  2 +-
 3 files changed, 7 insertions(+), 12 deletions(-)
Comment 16 Alessandro Sagratini 2026-10-14 16:25:12 UTC
I just tested the change on FreeBSD 15.1-p5 and hast indeed started working again.

I will obviously check in the next few days, but it's good to see it is back working :)