We've had that problem here as well with amtape.  It is hard to reproduce.

If it helps... I've recreated only once *and* .... it was in perl's DESTRUCTORs 
that it ran.

At least that's what I thought I could see via gdb.   If someone can recreate 
this consistently I'd really be glad to try and fix it.

As it is ... we will work soon on a solution to the tape locks such that a new 
lock can detect that all old ones are stale or useless and remove them.   That 
is our current planned workaround for amtape.

        -- CH

> -----Original Message-----
> From: [email protected] <owner-amanda-
> [email protected]> On Behalf Of Exuvo
> Sent: Thursday, March 10, 2022 8:22 PM
> To: Robert Heller <[email protected]>
> Cc: Nathan Stratton Treadway <[email protected]>; ? amanda users
> <[email protected]>
> Subject: Re: Problem with amtape "hanging" when forked from Java
>
> Also don't use stream.readAllBytes, it will block until the stream end is 
> reached
> ie the process exits and closes the stream. Which completely defeats the
> purpose of the waitFor.
>
> I suggest using something like:
>
> Process p = Runtime.getRuntime().exec(cmd); long start =
> System.currentTimeMillis(); InputStream out = p.getInputStream(); InputStream
> err = p.getErrorStream();
>
> while (p.isAlive() && System.currentTimeMillis() - start < 60 * 1000) {
>    if(out != null) {
>      int avail = out.available();
>      out.skip(avail); // or a read if you want the data
>    }
>    if(err != null) {
>      int avail = err.available();
>      err.skip(avail); // or a read if you want the data
>    }
>    Thread.sleep(1);
> }
>
> Anton "exuvo" Olsson
>     [email protected]
>
> On 2022-03-11 04:05, Exuvo wrote:
> > An educated guess from me would be that the particular error message you
> are waiting for is not actually written to stderror but normal output stream
> which you never read. Specifically this part of java.lang.Process 
> documentation
> "Because some native platforms only provide limited buffer size for standard
> input and output streams, failure to promptly write the input stream or read 
> the
> output stream of the subprocess may cause the subprocess to block, or even
> deadlock. ".
> >
> > Anton "exuvo" Olsson
> >    [email protected]
> >
> > On 2022-03-10 15:55, Robert Heller wrote:
> >> At Wed,  9 Mar 2022 22:50:29 -0500 (EST) Robert Heller
> <[email protected]> wrote:
> >>
> >>> At Wed, 9 Mar 2022 19:11:40 -0500 Nathan Stratton Treadway
> <[email protected]> wrote:
> >>>
> >>>> On Tue, Mar 08, 2022 at 18:27:47 -0500, Robert Heller wrote:
> >>>>> I've written a Java program that goes through vaulted tapes and
> >>>>> forks amtape (using Runtime.getRuntime().exec(()), and when a
> >>>>> non-existant tape label is asked for, amtape "hangs".  I cannot
> >>>>> figure out why or how to get amtape to just exit with an error (which I
> can then handle).
> >>>> Does it still hang if you pass an argument "-ointeractivity=''"
> >>>> when you exec amtape?
> >>> Did not try that.
> >> OK, it still hangs.
> >>
> >> Here is the Java fragment:
> >>
> >> public class FlushOldVaults extends BackupVault {
> >>      private static final String AMTAPE = "/usr/sbin/amtape";
> >>      private static final String AMTAPEOPT1 = "-otpchanger=vault_changer";
> >>      private static final String AMTAPEOPT2 = "-ointeractivity=";
> >>      private String amtape(String tape) throws Exception {
> >>          String cmd[] = new String[6];
> >>          cmd[0] = AMTAPE;
> >>          cmd[1] = AMTAPEOPT1;
> >>          cmd[2] = AMTAPEOPT2;
> >>          cmd[3] = configuration.AMCONFIG();
> >>          cmd[4] = "label";
> >>          cmd[5] = tape;
> >>          System.err.printf("*** FlushOldVaults.amtape(): tape is 
> >> '%s'\n",tape);
> >>          Process p = Runtime.getRuntime().exec(cmd);
> >>          InputStream err = p.getErrorStream();
> >>          if (err != null) err.readAllBytes();
> >>          if (!p.waitFor(60L, java.util.concurrent.TimeUnit.SECONDS)) {
> >>              System.err.printf("*** FlushOldVaults.amtape(): process 
> >> timeout\n");
> >>              String kill[] = new String[2];
> >>              kill[0] = "/bin/kill";
> >>              Long j = new Long(p.pid());
> >>              kill[1] = j.toString();
> >>              Process killproc = Runtime.getRuntime().exec(kill);
> >>              killproc.waitFor();
> >>          }
> >>          int status = p.waitFor();
> >>          System.err.printf("*** FlushOldVaults.amtape(): status = 
> >> %d\n",status);
> >>          if (status != 0) throw new Exception(AMTAPE+" "+AMTAPEOPT1+"
> "+AMTAPEOPT2+" "+configuration.AMCONFIG()+" label "+tape+": failed");
> >>          String tpchanger = amgetconf("CHANGER:vault_changer:tpchanger");
> >>          int colon = tpchanger.indexOf(':');
> >>          if (colon < 0) {
> >>              return tpchanger+"/data/";
> >>          } else {
> >>              return tpchanger.substring(colon+1)+"/data/";
> >>          }
> >>      }
> >> }
> >>
> >>
> >>>> If it does still hang, what do "lsof -p" and "strace -p" show on
> >>>> the amtape process while it's stuck?
> >>>>
> >>>>                             Nathan
> >>>>
> >>>> -------------------------------------------------------------------
> >>>> --------- Nathan Stratton Treadway  -  [email protected]  -
> >>>> Mid-Atlantic region Ray Ontko & Co.  -  Software consulting
> >>>> services  -
> https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.on
> tko.com%2F&amp;data=04%7C01%7Cchris.hassell%40betsol.com%7C4ecf8c0cf
> 57a48899f9708da030e5f26%7Cb0fb22a6306043889a97cdfc342994d8%7C0%7C
> 0%7C637825657540576785%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjA
> wMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&amp;sda
> ta=bNjOVKKGYm3iBIIV1BQk7qBo9Pr6yHUI%2BEPh4gjdDRc%3D&amp;reserved=
> 0
> >>>>   GPG Key:
> https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.on
> tko.com%2F~nathanst%2Fgpg_key.txt&amp;data=04%7C01%7Cchris.hassell%4
> 0betsol.com%7C4ecf8c0cf57a48899f9708da030e5f26%7Cb0fb22a6306043889a
> 97cdfc342994d8%7C0%7C0%7C637825657540576785%7CUnknown%7CTWFpb
> GZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6M
> n0%3D%7C2000&amp;sdata=JpawroAwKI503p0a6aUu%2FP8prZ1oeiGP7DIySMK
> 2uro%3D&amp;reserved=0   ID: 1023D/ECFB6239
> >>>>   Key fingerprint = 6AD8 485E 20B9 5C71 231C  0C32 15F3 ADCD ECFB
> >>>> 6239
> >>>>
> >>>>
Confidentiality Notice | The information transmitted by this email is intended 
only for the person or entity to which it is addressed. This email may contain 
proprietary, business-confidential and/or privileged material. If you are not 
the intended recipient of this message, be aware that any use, review, 
re-transmission, distribution, reproduction or any action taken in reliance 
upon this message is strictly prohibited. If you received this in error, please 
contact the sender and delete the material from all computers.

Reply via email to