diff --git a/gst/gstbin.c b/gst/gstbin.c
index 8cac943..b69b9b2 100644
--- a/gst/gstbin.c
+++ b/gst/gstbin.c
@@ -2994,6 +2994,17 @@ gst_bin_handle_message_func (GstBin * bin, GstMessage * message)
       GST_MESSAGE_TYPE_NAME (message));
 
   switch (type) {
+    case GST_MESSAGE_ERROR:
+    {
+      GST_OBJECT_LOCK (bin);
+      /* flag error */
+      GST_DEBUG_OBJECT (bin, "got ERROR message, unlocking state change");
+      GST_STATE_RETURN (bin) = GST_STATE_CHANGE_FAILURE;
+      GST_STATE_BROADCAST (bin);
+      GST_OBJECT_UNLOCK (bin);
+
+      goto forward;
+    }
     case GST_MESSAGE_EOS:
     {
       gboolean eos;
diff --git a/gst/gstelement.c b/gst/gstelement.c
index 92d755d..0144de5 100644
--- a/gst/gstelement.c
+++ b/gst/gstelement.c
@@ -1949,7 +1949,7 @@ gst_element_get_state_func (GstElement * element,
   GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, element, "RETURN is %s",
       gst_element_state_change_return_get_name (ret));
 
-  /* we got an error, report immediatly */
+  /* we got an error, report immediately */
   if (ret == GST_STATE_CHANGE_FAILURE)
     goto done;
 
diff --git a/tests/check/gst/gstbin.c b/tests/check/gst/gstbin.c
index d466a28..6548093 100644
--- a/tests/check/gst/gstbin.c
+++ b/tests/check/gst/gstbin.c
@@ -441,9 +441,52 @@ GST_START_TEST (test_watch_for_state_change)
   gst_object_unref (bus);
   gst_object_unref (bin);
 }
+GST_END_TEST;
+
+GST_START_TEST (test_state_change_error_message)
+{
+  GstElement *src, *sink, *bin;
+  GstBus *bus;
+  GstStateChangeReturn ret;
+
+  bin = gst_element_factory_make ("bin", NULL);
+  fail_unless (bin != NULL, "Could not create bin");
 
+  bus = g_object_new (gst_bus_get_type (), NULL);
+  gst_element_set_bus (GST_ELEMENT_CAST (bin), bus);
+
+  src = gst_element_factory_make ("fakesrc", NULL);
+  fail_if (src == NULL, "Could not create fakesrc");
+  sink = gst_element_factory_make ("fakesink", NULL);
+  fail_if (sink == NULL, "Could not create fakesink");
+
+  /* add but don't link elements */
+  gst_bin_add (GST_BIN (bin), sink);
+  gst_bin_add (GST_BIN (bin), src);
+
+  /* change state, this should succeed */
+  ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
+  fail_unless (ret == GST_STATE_CHANGE_ASYNC);
+
+  /* now wait, the streaming thread will error because the source is not
+   * linked. */
+  ret = gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
+      GST_CLOCK_TIME_NONE);
+  fail_unless (ret == GST_STATE_CHANGE_FAILURE);
+
+  gst_bus_set_flushing (bus, TRUE);
+
+  /* setting bin to NULL flushes the bus automatically */
+  ret = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
+  fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
+
+  /* clean up */
+  gst_object_unref (bus);
+  gst_object_unref (bin);
+}
 GST_END_TEST;
 
+
 /* adding an element with linked pads to a bin unlinks the
  * pads */
 GST_START_TEST (test_add_linked)
@@ -988,6 +1031,7 @@ gst_bin_suite (void)
   tcase_add_test (tc_chain, test_message_state_changed_child);
   tcase_add_test (tc_chain, test_message_state_changed_children);
   tcase_add_test (tc_chain, test_watch_for_state_change);
+  tcase_add_test (tc_chain, test_state_change_error_message);
   tcase_add_test (tc_chain, test_add_linked);
   tcase_add_test (tc_chain, test_add_self);
   tcase_add_test (tc_chain, test_iterate_sorted);
