Subject: Re: Areas interaction causes nncp-toss to always exit with error

From: Sergey Matveev <[email-masked]>
Date: Sun, 31 Oct 2021 17:01:39 +0300

Greetings!

*** John Goerzen [2021-10-30 10:15]:
>So I'm doing some more tracking down on this issue with nncp-toss
>existing with an error and never advancing certain packets on to their
>destination.

Accidentally I repeated the same behaviour on one of my computers.
"already seen" log message, then "tossing" message and then bad exit
code without exact errors. I send area packet with nncp-file ... area:...,
then remembered that NNCP is not the latest version on that computer,
upgraded it and run nncp-toss, catching that bad behaviour. nncp-file
used an old code with ".seen" packets, but new one does not use ".seen"
extension anymore. So nncp-toss did not see self-seen packet, that will
forcefully remove the packet from self directory after it was sent to
all "subs".

When you run nncp-toss, it has the following code:

-----# 1 [                              src/cmd/nncp-toss/main.go ]-----
 115 			if nodeId == *ctx.SelfId {
 116 				isBad = ctx.Toss(
 117 					node.Id,
 118 					nncp.TTx,
 119 					nice,
 120 					*dryRun, false, true, true, true, true, *noArea,
 121 				) || isBad
 122 			}
---------------------------------- >8 ----------------------------------

calling toss with noFile argument set to true (sigh, I already should
create TossOption struct to pass those arguments more human readably).
Because there is no seen-file, it tries to process the packet as it was
sent from outside. But because noFile is set, it quietly returns no
error:

-----# 2 [                                            src/toss.go ]-----
 242 	case PktTypeFile:
 243 		if noFile {
 244 			return nil
 245 		}
---------------------------------- >8 ----------------------------------

but PktEncRead code below does not expect that pipe won't be filled with
anything, so actually there is error "io: read/write on closed pipe",
that is logged with LogE I added now. Previously it was "unseen".

-----# 3 [                                            src/toss.go ]-----
 684 	case PktTypeArea:
 812 		if area.Prv == nil {
 817 		} else {
 868 			_, _, _, err = PktEncRead(
 869 				&areaNodeOur,
 870 				ctx.Neigh,
 871 				fullPipeR,
 872 				pipeW,
 873 				signatureVerify,
 874 				nil,
 875 			)
 876 			if err != nil {
 877 				ctx.LogE("rx-area-pkt-enc-read2", les, err, logMsg)
 878 				pipeW.CloseWithError(err)
 879 				<-errs
 880 				return err
 881 			}
---------------------------------- >8 ----------------------------------

seen-packet is created when nncp-file/whatever creates outgoing area
packet. In my case it faulted because of different NNCP version.
Probably something similar on your side?

I have completely not looked at NNCP for a long time, sorry. And still
have not enough time to dive in all that error-related issues.

-- 
Sergey Matveev (http://www.stargrave.org/)
OpenPGP: CF60 E89A 5923 1E76 E263  6422 AE1A 8109 E498 57EF