Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-13865

Jenkins /queue/api does not produce properly formatted JSON when a build in queue where the destination node/s are busy.

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • core
    • None
    • Linux

      Jenkins /queue/api does not produce properly formatted JSON when build in queue where a node/s are fully busy. The json produced is un-parsable. This can be visible on the builds.apache.org server.

      Example:
      "why":"Waiting for next available executor on

      [8mha:AAAAkB+LCAAAAAAAAABb85aBtbiIQSajNKU4P08vOT+vOD8nVc+jsiC1KCczL9svvyT1dMUiOWdZ/mImBiZPBrac1Lz0kgwfBubSopwSBiGfrMSyRP2cxLx0/eCSosy8dOuKIgYpNOOcITTIMAYIYGRiYKgoADLYShgE9JPzcwtKS1KL9HNKk1PzUgENqikilQAAAA==[0mlucene"
      

      Appears that the "why" property of the queued build isn't being formatted properly. Actually it's being gzipped...

      Looking at the source, the hudson.model.queue.CauseOfBlockage class appears to be the culprit. To wit:

      public String getShortDescription() {
                  return Messages.Queue_WaitingForNextAvailableExecutorOn(HyperlinkNote.encodeTo("/computer/"+ node.getNodeName(), node.getNodeName()));
              }
      

      The nodename is attempting to be encoded with HyperlinkNote:

      public static String encodeTo(String url, String text) {
              try {
                  return new HyperlinkNote(url,text.length()).encode()+text;
              } catch (IOException e) {
                  // impossible, but don't make this a fatal problem
                  LOGGER.log(Level.WARNING, "Failed to serialize "+HyperlinkNote.class,e);
                  return text;
              }
          }
      

      Which calls the supers encode() method:

      public String encode() throws IOException {
              return encodeToBytes().toString();
          }
      

      And finally encodeToBytes():

      private ByteArrayOutputStream encodeToBytes() throws IOException {
              ByteArrayOutputStream buf = new ByteArrayOutputStream();
              ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(buf));
              oos.writeObject(this);
              oos.close();
      
              ByteArrayOutputStream buf2 = new ByteArrayOutputStream();
      
              DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null));
              buf2.write(PREAMBLE);
              dos.writeInt(buf.size());
              buf.writeTo(dos);
              dos.close();
              buf2.write(POSTAMBLE);
              return buf2;
          }
      

      Finally in ConsoleNote

      public static final String PREAMBLE_STR = "\u001B[8mha:";
      public static final String POSTAMBLE_STR = "\u001B[0m";
      }
      

      Clearly the choice in using ansi escaping, and therefore the brackets is violating the JSON structural syntax rules and causing the JSON emitted to be un-parsable.

          [JENKINS-13865] Jenkins /queue/api does not produce properly formatted JSON when a build in queue where the destination node/s are busy.

          Jason Howk added a comment -

          One more update: This appears to be due to the chosen preamble/postamble chosen.

          public static final String PREAMBLE_STR = "\u001B[8mha:";
          public static final String POSTAMBLE_STR = "\u001B[0m";

          Per RFC, JSON is unicode. (http://www.ietf.org/rfc/rfc4627) and the choice of the ascii control codes violates the JSON agreement (i.e. use of the brackets as they are structural characters)

          Jason Howk added a comment - One more update: This appears to be due to the chosen preamble/postamble chosen. public static final String PREAMBLE_STR = "\u001B[8mha:"; public static final String POSTAMBLE_STR = "\u001B[0m"; Per RFC, JSON is unicode. ( http://www.ietf.org/rfc/rfc4627 ) and the choice of the ascii control codes violates the JSON agreement (i.e. use of the brackets as they are structural characters)

          Jason Howk added a comment -

          What we need is not to use the ansi escape codes. Something like this? http://rtomayko.github.com/bcat/a2h.1.html

          Jason Howk added a comment - What we need is not to use the ansi escape codes. Something like this? http://rtomayko.github.com/bcat/a2h.1.html

          Jason Howk added a comment -

          Looks like the issue was due to commit ff4b0255 where description was, "Added another hyperlink to the console output of a blocked matrix build configuration."

          Jason Howk added a comment - Looks like the issue was due to commit ff4b0255 where description was, "Added another hyperlink to the console output of a blocked matrix build configuration."

          Jason Howk added a comment -

          And fixed in 2128c9d7

          Jason Howk added a comment - And fixed in 2128c9d7

          Bernd bep added a comment -

          In what version was this fixed?

          I noticed the same problem also for XML returned from /queue/api/xml (Jenkins 1.466.1)

          Bernd bep added a comment - In what version was this fixed? I noticed the same problem also for XML returned from /queue/api/xml (Jenkins 1.466.1)

          Jesse Glick added a comment -

          @bep 2128c9d7 is in 1.467.

          Jesse Glick added a comment - @bep 2128c9d7 is in 1.467.

          Bernd bep added a comment -

          1.480.3 fixes the XML related issue reported by me above.

          thanks everyone!

          Bernd bep added a comment - 1.480.3 fixes the XML related issue reported by me above. thanks everyone!

          Patrick Byrne added a comment -

          Running 1.506 and we are seeing this log file 'decoration' when color xterm output is turned on.

          Patrick Byrne added a comment - Running 1.506 and we are seeing this log file 'decoration' when color xterm output is turned on.

          Jesse Glick added a comment -

          Looks like this was fixed long ago.

          Jesse Glick added a comment - Looks like this was fixed long ago.

            Unassigned Unassigned
            flyingfish Jason Howk
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: